Re: Long long int's and sprintf

From: Mike Stilson (mike@c746148-a.ehlls1.pa.home.com)
Date: 06/16/01


On Sat, Jun 16, 2001 at 02:56:49PM -0700, Daniel A. Koepke came up with this idea:
> On Sat, 16 Jun 2001, Mike Stilson wrote:
>
> > side note: I didn't get them with gcc 2.95.2 complaining about the
> > signedness of %Lu or %Ld that I can remember, although I did get the
> > errors at comparisons on a few scattered lines.  Did that switch long
> > time ago though so I might be forgetting too.
>
> You're right.  I don't know why it doesn't complain about the signedness.
> I think it should, especially with -Wall.  But, suffice it to say, it
> doesn't warn you about it.
>

Just for the archives, here's a little example (might help someone with
the compiler errors down the road if they bother to check archives)

/* Example of compiler warnings and munged ouput of messing up with
 * unsigned long long's
 */
#include <stdio.h>

int main()
{
        unsigned long long int bignum = 12345678901234567890UL;

        printf("%Lu %Ld %ld %lu %d\n", bignum, bignum, bignum, bignum, bignum);
        exit(0);
}

$ gcc -Wall -o test test.c
test.c: In function `main':
test.c:7: warning: long int format, different type arg (arg 4)
test.c:7: warning: long unsigned int format, different type arg (arg 5)
test.c:7: warning: int format, different type arg (arg 6)

$ ./test
12345678901234567890 -6101065172474983726 -1420514932 3944680146 -1420514932


>> tested, retested, beat on, fed bogus data, you name it; it works fine.
>> (suppose I coulda used digits too, just didn't)
>
> The problem with using digits is that you could have "1234".  Now is this
> a number representing
>   (1 << 1) | (1 << 4) | (1 << 6) | (1 << 7) | (1 << 10)
> or if it's an ASCII representation of
>   (1 << 54) | (1 << 55) | (1 << 56) | (1 << 57)
> assuming that 0-9 follow A-Z in flags[]?  You can't tell.
>

I knew there was a reason I didn't.  That was it.  I just remembered I wasn't
too thrilled with using the symbols because of some possible parsing error
down the road.

Again though, it comes down to the idea that if you can control the input fed
to it, it would be doable.  Just have to be more careful.  More likely to let
1234 slip through than "Aaq$!"

-mike

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/05/01 PST