diff options
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r-- | lib/vsprintf.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 4ee19d0d3910..7af9d841c43b 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c | |||
@@ -146,19 +146,16 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res) | |||
146 | { | 146 | { |
147 | char *tail; | 147 | char *tail; |
148 | unsigned long val; | 148 | unsigned long val; |
149 | size_t len; | ||
150 | 149 | ||
151 | *res = 0; | 150 | *res = 0; |
152 | len = strlen(cp); | 151 | if (!*cp) |
153 | if (len == 0) | ||
154 | return -EINVAL; | 152 | return -EINVAL; |
155 | 153 | ||
156 | val = simple_strtoul(cp, &tail, base); | 154 | val = simple_strtoul(cp, &tail, base); |
157 | if (tail == cp) | 155 | if (tail == cp) |
158 | return -EINVAL; | 156 | return -EINVAL; |
159 | 157 | ||
160 | if ((*tail == '\0') || | 158 | if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) { |
161 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | ||
162 | *res = val; | 159 | *res = val; |
163 | return 0; | 160 | return 0; |
164 | } | 161 | } |
@@ -220,18 +217,15 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res) | |||
220 | { | 217 | { |
221 | char *tail; | 218 | char *tail; |
222 | unsigned long long val; | 219 | unsigned long long val; |
223 | size_t len; | ||
224 | 220 | ||
225 | *res = 0; | 221 | *res = 0; |
226 | len = strlen(cp); | 222 | if (!*cp) |
227 | if (len == 0) | ||
228 | return -EINVAL; | 223 | return -EINVAL; |
229 | 224 | ||
230 | val = simple_strtoull(cp, &tail, base); | 225 | val = simple_strtoull(cp, &tail, base); |
231 | if (tail == cp) | 226 | if (tail == cp) |
232 | return -EINVAL; | 227 | return -EINVAL; |
233 | if ((*tail == '\0') || | 228 | if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) { |
234 | ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) { | ||
235 | *res = val; | 229 | *res = val; |
236 | return 0; | 230 | return 0; |
237 | } | 231 | } |