public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Re: There is a bug on sprintf newlib when using specifier %-*.llu
       [not found] <KL1PR0601MB3671369FA0B338FB2D347AEFCDE00@KL1PR0601MB3671.apcprd06.prod.outlook.com>
@ 2020-03-07 11:39 ` Richard Damon
  0 siblings, 0 replies; only message in thread
From: Richard Damon @ 2020-03-07 11:39 UTC (permalink / raw)
  To: newlib

On 3/7/20 3:30 AM, ng boon khai wrote:
> Hi,
>
> I found a bug when using the newlib sprinf using the spcifier %-*.llu
>
> Below is the code snippet
>
> function (){
>    int64_t longval;
>    longval=(int64_t)(1);
>    char comparebuf[2000];
>    sprintf(comparebuf, "testing string! arg1=%-*.llu, arg2=%-*.llu",1,longval,1,longval);
>    printf(comparebuf);
> }
>
> And i get this outcome
> testing string! arg1=499644, arg2=
>
> Expected outcome should be
> testing string! arg1=1, arg2=1
>
> Regards,
> Ng Boon Khai.
>
One issue with your program is that you have a variable of type int64_t 
but using a format that expects an unsigned long long.

In some implementations, long long might be 64 bits, but in others long 
long will be 128 bits.

If you want to print an int64_t, you should be using the format 
specified from the macro PRId64

If you want to use llu, you should be using a variable of type unsigned 
long long

-- 
Richard Damon


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-07 11:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <KL1PR0601MB3671369FA0B338FB2D347AEFCDE00@KL1PR0601MB3671.apcprd06.prod.outlook.com>
2020-03-07 11:39 ` There is a bug on sprintf newlib when using specifier %-*.llu Richard Damon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).