Unverified Commit 4056542b by Evgeny Vereshchagin Committed by Christian Brauner

string_utils: get around GCC-11 false positives

by getting rid of stpncpy Tested with gcc (GCC) 11.1.1 20210428 (Red Hat 11.1.1-1) Closes https://github.com/lxc/lxc/issues/3752Signed-off-by: 's avatarEvgeny Vereshchagin <evvers@ya.ru>
parent 15e2d139
...@@ -877,14 +877,18 @@ int parse_byte_size_string(const char *s, long long int *converted) ...@@ -877,14 +877,18 @@ int parse_byte_size_string(const char *s, long long int *converted)
char *end; char *end;
char dup[INTTYPE_TO_STRLEN(long long int)] = {0}; char dup[INTTYPE_TO_STRLEN(long long int)] = {0};
char suffix[3] = {0}; char suffix[3] = {0};
size_t len;
if (is_empty_string(s)) if (!s)
return ret_errno(EINVAL); return ret_errno(EINVAL);
end = stpncpy(dup, s, sizeof(dup) - 1); len = strlen(s);
if (*end != '\0') if (len == 0 || len > sizeof(dup) - 1)
return ret_errno(EINVAL); return ret_errno(EINVAL);
memcpy(dup, s, len);
end = dup + len;
if (isdigit(*(end - 1))) if (isdigit(*(end - 1)))
suffix_len = 0; suffix_len = 0;
else if (isalpha(*(end - 1))) else if (isalpha(*(end - 1)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment