summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorNick Kew <niq@apache.org>2018-07-23 22:28:23 +0000
committerNick Kew <niq@apache.org>2018-07-23 22:28:23 +0000
commite699f01c350ebd629f8faa828167cc83ec50fbc4 (patch)
tree777f0842a73e52e883f7c590393829d185884d26 /strings
parente6e73e86a9f8b8d8c8f3597aa48ae981f18ef14d (diff)
downloadapr-e699f01c350ebd629f8faa828167cc83ec50fbc4.tar.gz
PR 62555: fix edge-case int overflow in apr_itoa
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1836519 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-rw-r--r--strings/apr_strings.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/strings/apr_strings.c b/strings/apr_strings.c
index 0ba49c844..beca6d480 100644
--- a/strings/apr_strings.c
+++ b/strings/apr_strings.c
@@ -362,19 +362,21 @@ APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n)
const int BUFFER_SIZE = sizeof(int) * 3 + 2;
char *buf = apr_palloc(p, BUFFER_SIZE);
char *start = buf + BUFFER_SIZE - 1;
+ unsigned int un;
int negative;
if (n < 0) {
negative = 1;
- n = -n;
+ un = -n;
}
else {
negative = 0;
+ un = n;
}
*start = 0;
do {
- *--start = '0' + (n % 10);
- n /= 10;
- } while (n);
+ *--start = '0' + (un % 10);
+ un /= 10;
+ } while (un);
if (negative) {
*--start = '-';
}
@@ -387,18 +389,20 @@ APR_DECLARE(char *) apr_ltoa(apr_pool_t *p, long n)
char *buf = apr_palloc(p, BUFFER_SIZE);
char *start = buf + BUFFER_SIZE - 1;
int negative;
+ unsigned int un;
if (n < 0) {
negative = 1;
- n = -n;
+ un = -n;
}
else {
negative = 0;
+ un = n;
}
*start = 0;
do {
- *--start = (char)('0' + (n % 10));
- n /= 10;
- } while (n);
+ *--start = (char)('0' + (un % 10));
+ un /= 10;
+ } while (un);
if (negative) {
*--start = '-';
}