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

Summary: Obvious bugs in SDL_ltoa and SDL_lltoa
Product: SDL Reporter: pjz <acme_pjz>
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: r.kreis
Version: 2.0.0   
Hardware: All   
OS: All   
Attachments: fix SDL_ltoa and SDL_lltoa for minimum values
do fix SDL_ltoa and SDL_lltoa for minimum values

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