summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@webkeks.org>2010-12-26 03:47:44 +0100
committerJonathan Schleifer <js@webkeks.org>2010-12-26 03:47:44 +0100
commit1270b0e3bdf860eda25a06f4679a2e5e2718dd67 (patch)
treeef1be8954e98ed640225844cc9f2fd69773a57ec
parent3ed01e20ea9a3d6ad42231ccc2d92869c1b9dcf5 (diff)
Nicer overflow check in -[decimalValue].
-rw-r--r--src/OFString.m7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/OFString.m b/src/OFString.m
index ff05494e..e5bcde52 100644
--- a/src/OFString.m
+++ b/src/OFString.m
@@ -976,13 +976,12 @@ of_string_index_to_position(const char *str, size_t idx, size_t len)
for (; i < length; i++) {
if (string[i] >= '0' && string[i] <= '9') {
- intmax_t newnum = (num * 10) + (string[i] - '0');
-
- if (newnum < num)
+ if (INTMAX_MAX / 10 < num ||
+ INTMAX_MAX - num * 10 < string[i] - '0')
@throw [OFOutOfRangeException
newWithClass: isa];
- num = newnum;
+ num = (num * 10) + (string[i] - '0');
} else
@throw [OFInvalidEncodingException newWithClass: isa];
}