Fix dehumanize_number() to correctly detect overflows

Do not allow numbers greated than INT64_MAX and smaller than INT64_MIN.
Clarify the positive sign value by prefixing it with an explicit +.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=66909
This commit is contained in:
Guillem Jover
2013-07-15 01:44:30 +02:00
parent 119417462e
commit 61b2dbb8f5
2 changed files with 23 additions and 4 deletions

View File

@@ -25,6 +25,7 @@
*/
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
int
@@ -60,5 +61,17 @@ main(int argc, char **argv)
assert(dehumanize_number("-3G", &val) == 0);
assert(val == -3221225472LL);
assert(dehumanize_number("9223372036854775807", &val) == 0);
assert(val == INT64_MAX);
assert(dehumanize_number("9223372036854775808", &val) == -1);
assert(errno == ERANGE);
assert(dehumanize_number("-9223372036854775808", &val) == 0);
assert(val == INT64_MIN);
assert(dehumanize_number("-9223372036854775809", &val) == -1);
assert(errno == ERANGE);
return 0;
}