From 566b384e4e863162f9fbb2a0dd856e03fe305b90 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 30 Apr 2025 05:15:22 +0200 Subject: [PATCH] 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. --- include/haproxy/tools.h | 2 +- src/tools.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 34173d76f..45e0ff994 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -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 characters from 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 diff --git a/src/tools.c b/src/tools.c index a8aaccd9f..6c4dd7dfa 100644 --- a/src/tools.c +++ b/src/tools.c @@ -2968,9 +2968,9 @@ bad_input: } /* copies at most characters from 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])