We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2050 - Obvious bugs in SDL_ltoa and SDL_lltoa
Summary: Obvious bugs in SDL_ltoa and SDL_lltoa
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.0
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-21 13:56 UTC by pjz
Modified: 2013-12-12 05:20 UTC (History)
1 user (show)

See Also:


Attachments
fix SDL_ltoa and SDL_lltoa for minimum values (1.29 KB, patch)
2013-12-11 10:24 UTC, r.kreis
Details | Diff
do fix SDL_ltoa and SDL_lltoa for minimum values (1.29 KB, patch)
2013-12-11 10:29 UTC, r.kreis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pjz 2013-08-21 13:56:06 UTC
SDL_ltoa(-2147483648,s,10) only returns "-" because there is a bug in the code: 

    if ( value < 0 ) {
        *bufp++ = '-';
        value = -value;
    }

but -(-2147483648) is still -2147483648 (0x80000000) as signed int (or long), so the following loop doesn't run at all. Similar bug are also in SDL_lltoa.

BTW, there is no sanity check for radix.
Comment 1 r.kreis 2013-12-11 10:24:38 UTC
Created attachment 1486 [details]
fix SDL_ltoa and SDL_lltoa for minimum values

Simply making SDL_ltoa/SDL_lltoa use SDL_ultoa/SDL_ulltoa with the absolute (and thus unsigned) value fixes this.
Comment 2 r.kreis 2013-12-11 10:29:37 UTC
Created attachment 1487 [details]
do fix SDL_ltoa and SDL_lltoa for minimum values

This one actually uses SDL_ulltoa inside SDL_lltoa, as promised.
Comment 3 Sam Lantinga 2013-12-12 05:20:29 UTC
Good catch, thanks!
https://hg.libsdl.org/SDL/rev/8e4512b74223