Skip to contentSkip to conversation

lib/kstrtox.c Stop parsing integer on overflow

PATCH New Anshul Garg 1 participant 1 message Jan 22, 2015 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/kstrtox.c Stop parsing integer on overflow

From: Anshul Garg <[email protected]>

While converting string representation to integer
break the loop if overflow is detected.

---
 lib/kstrtox.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kstrtox.c +3 -1
index ec8da78..6f30209 100644
@@ -70,8 +70,10 @@ unsigned int _parse_integer(const char *s, unsigned int base, unsigned long long
 		 * it in the max base we support (16)
 		 */
 		if (unlikely(res & (~0ull << 60))) {
-			if (res > div_u64(ULLONG_MAX - val, base))
+			if (res > div_u64(ULLONG_MAX - val, base)) {
 				overflow = 1;
+				break;
+			}
 		}
 		res = res * base + val;
 		rv++;
Signature · 6 lines
1.7.9.5


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com