about summary refs log tree commit diff
path: root/src/stdlib/atoi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib/atoi.c')
-rw-r--r--src/stdlib/atoi.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/stdlib/atoi.c b/src/stdlib/atoi.c
index 648b154f..9baca7b8 100644
--- a/src/stdlib/atoi.c
+++ b/src/stdlib/atoi.c
@@ -9,7 +9,8 @@ int atoi(const char *s)
 	case '-': neg=1;
 	case '+': s++;
 	}
+	/* Compute n as a negative number to avoid overflow on INT_MIN */
 	while (isdigit(*s))
-		n = 10*n + *s++ - '0';
-	return neg ? -n : n;
+		n = 10*n - (*s++ - '0');
+	return neg ? n : -n;
 }