MINOR: tools: make my_strndup() take a size_t len instead of and int

In relation to issue #2954, it appears that turning some size_t length
calculations to the int that uses my_strndup() upsets coverity a bit.
Instead of dealing with such warnings each time, better address it at
the root. An inspection of all call places show that the size passed
there is always positive so we can safely use an unsigned type, and
size_t will always suit it like for strndup() where it's available.
This commit is contained in:
Willy Tarreau 2025-04-30 05:15:22 +02:00
parent 5f9ce99c79
commit 566b384e4e
2 changed files with 3 additions and 3 deletions

View File

@ -674,7 +674,7 @@ extern const char *parse_size_ull(const char *text, ullong *ret);
int parse_binary(const char *source, char **binstr, int *binstrlen, char **err);
/* copies at most <n> characters from <src> and always terminates with '\0' */
char *my_strndup(const char *src, int n);
char *my_strndup(const char *src, size_t n);
/*
* search needle in haystack

View File

@ -2968,9 +2968,9 @@ bad_input:
}
/* copies at most <n> characters from <src> and always terminates with '\0' */
char *my_strndup(const char *src, int n)
char *my_strndup(const char *src, size_t n)
{
int len = 0;
size_t len = 0;
char *ret;
while (len < n && src[len])