Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » 64bit fix for jpgalleg

Credits go to Goalie Ca for helping out!
This thread is locked; no one can reply to it. rss feed Print
64bit fix for jpgalleg
tobing
Member #5,213
November 2004
avatar

Hi allegators,

when compiling with MSVC 7.1 and enabled warnings for 64bit issues, I have seen that

extern void _jpeg_chunk_puts(unsigned char *, int);

should be changed to

extern void _jpeg_chunk_puts(unsigned char *, size_t);

in internal.h and io.c.

Do you need a patch file for this? Should I send a mail to the AD mailing list?

Goalie Ca
Member #2,579
July 2002
avatar

It is actually a signedness warning and would affect 32-bit platforms as well. strlen returns size_t while the function takes an int.

I checked in the fix and chose to cast the line to (int). This doesn't change the logic, just gets rid of the warning. This is just a com chunk in the jpeg file header. The rest of the file/logic would need to be converted to size_t to get > 2GB files. I don't suppose the jpeg spec event supports that.

-------------
Bah weep granah weep nini bong!

tobing
Member #5,213
November 2004
avatar

Well, thanks...

Of course that is one way of doing it, and it's no problem in regard of the file sizes. ;) One thing might be considered though: using int would also accept negative values, which would be an error. Having the unsigned type in the argument list, it would be a lot harder to call it wrong. Well, probably not an issue though, because it's an internal function...

Goalie Ca
Member #2,579
July 2002
avatar

Well in this case (int) strlen won't cause a negative number. And negative numbers wouldn't do anything anyways.. it would be like sending a zero.

I opted to not change anything instead of looking for all the loops and counters that use int instead of size_t. Sometimes it can be nice to have ssize_t for crazy pointer arith too.

Anyways, thanks for pointing out the warning.

-------------
Bah weep granah weep nini bong!

tobing
Member #5,213
November 2004
avatar

Quote:

Well in this case (int) strlen won't cause a negative number.

That's right...

Quote:

And negative numbers wouldn't do anything anyways.. it would be like sending a zero.

but this is not, if you look at the code:

  for (; size; size--)
    _jpeg_chunk_putc(*s++);

IF size is negative, then this loop would have many iterations until overflow, then counts down another 2 billion iterations. ;) Looks like the loop was written with the assumption that size may not be negative...

Goalie Ca
Member #2,579
July 2002
avatar

You're right.. I forgot what the code was again. I had pictured a while loop instead.

-------------
Bah weep granah weep nini bong!

Go to: