Commit 559b140a36613bb5b63f258b2ad833dad8cd11d9

Authored by Michal Nazarewicz
Committed by Linus Torvalds
1 parent e3f76e3386

lib: vsprintf: useless strlen() removed

The strict_strtoul() and strict_strtoull() functions used strlen() to
check argument's length in a situation where it wasn't strictly necessary

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Cc: "Yi Yang" <yi.y.yang@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 4 additions and 10 deletions Side-by-side Diff

... ... @@ -146,19 +146,16 @@
146 146 {
147 147 char *tail;
148 148 unsigned long val;
149   - size_t len;
150 149  
151 150 *res = 0;
152   - len = strlen(cp);
153   - if (len == 0)
  151 + if (!*cp)
154 152 return -EINVAL;
155 153  
156 154 val = simple_strtoul(cp, &tail, base);
157 155 if (tail == cp)
158 156 return -EINVAL;
159 157  
160   - if ((*tail == '\0') ||
161   - ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
  158 + if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
162 159 *res = val;
163 160 return 0;
164 161 }
165 162  
166 163  
... ... @@ -220,18 +217,15 @@
220 217 {
221 218 char *tail;
222 219 unsigned long long val;
223   - size_t len;
224 220  
225 221 *res = 0;
226   - len = strlen(cp);
227   - if (len == 0)
  222 + if (!*cp)
228 223 return -EINVAL;
229 224  
230 225 val = simple_strtoull(cp, &tail, base);
231 226 if (tail == cp)
232 227 return -EINVAL;
233   - if ((*tail == '\0') ||
234   - ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
  228 + if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
235 229 *res = val;
236 230 return 0;
237 231 }