]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: make my_strndup() take a size_t len instead of and int
authorWilly Tarreau <w@1wt.eu>
Wed, 30 Apr 2025 03:15:22 +0000 (05:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 30 Apr 2025 03:17:43 +0000 (05:17 +0200)
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.

include/haproxy/tools.h
src/tools.c

index 34173d76f4c9a2b9c94fb394421bb263cef7bc89..45e0ff994f9f9ade484d0a26ba451f67d812eea7 100644 (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
index a8aaccd9f0745efaceddf11379d10c5b2f192c38..6c4dd7dfa218d2ead1e31c50572988a2f8b68435 100644 (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])