mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-04 13:21:45 +00:00
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>
This commit is contained in:
parent
e3f76e3386
commit
559b140a36
1 changed files with 4 additions and 10 deletions
|
@ -146,19 +146,16 @@ int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)
|
||||||
{
|
{
|
||||||
char *tail;
|
char *tail;
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
*res = 0;
|
*res = 0;
|
||||||
len = strlen(cp);
|
if (!*cp)
|
||||||
if (len == 0)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
val = simple_strtoul(cp, &tail, base);
|
val = simple_strtoul(cp, &tail, base);
|
||||||
if (tail == cp)
|
if (tail == cp)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if ((*tail == '\0') ||
|
if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
|
||||||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
|
|
||||||
*res = val;
|
*res = val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -220,18 +217,15 @@ int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)
|
||||||
{
|
{
|
||||||
char *tail;
|
char *tail;
|
||||||
unsigned long long val;
|
unsigned long long val;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
*res = 0;
|
*res = 0;
|
||||||
len = strlen(cp);
|
if (!*cp)
|
||||||
if (len == 0)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
val = simple_strtoull(cp, &tail, base);
|
val = simple_strtoull(cp, &tail, base);
|
||||||
if (tail == cp)
|
if (tail == cp)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if ((*tail == '\0') ||
|
if ((tail[0] == '\0') || (tail[0] == '\n' && tail[1] == '\0')) {
|
||||||
((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {
|
|
||||||
*res = val;
|
*res = val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue