apr-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 62555] New: apr_itoa incorrectly shows least integer value (-2147483648)
Date Thu, 19 Jul 2018 06:58:21 GMT

            Bug ID: 62555
           Summary: apr_itoa incorrectly shows least integer value
           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);
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

View raw message