You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bugs@apr.apache.org by bu...@apache.org on 2018/07/19 06:58:21 UTC

[Bug 62555] New: apr_itoa incorrectly shows least integer value (-2147483648)

https://bz.apache.org/bugzilla/show_bug.cgi?id=62555

            Bug ID: 62555
           Summary: apr_itoa incorrectly shows least integer value
                    (-2147483648)
           Product: APR
           Version: HEAD
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: APR
          Assignee: bugs@apr.apache.org
          Reporter: afk@inbox.ru
  Target Milestone: ---

apr_itoa unable to convert -2147483648 (the least possible negative integer) to
a string, below is test:

----------------
int v=-2147483648LL;
const char *tobe = apr_psprintf(pool, "%i", v);
const char *incorrect = apr_itoa(pool, v);
printf("tobe=%s, incorrect=%s", tobe, incorrect);
----------------
result:
tobe=-2147483648, incorrect=-./,),(-*,(


The reason is that apr_itoa tries to convert negative integer to positive,
which is not possible:

apr_strings.c, line 359

if (n < 0) {
    negative = 1;
    n = -n;  // <--- integer overflow in case of -2147483648
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org


[Bug 62555] apr_itoa incorrectly shows least integer value (-2147483648)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62555

--- Comment #1 from Nick Kew <ni...@webthing.com> ---
This appears to be repeated also in apr_ltoa and apr_off_t_toa.  Trivial to fix
in itoa and ltoa with assignment to unsigned.  Not sure about off_t: it should
work the same way but I don't know OTTOMH how to express it.  Probably
superfluous in any case.

Does r1836519 work for you?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@apr.apache.org
For additional commands, e-mail: bugs-help@apr.apache.org