qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] block/curl: use strlen instead of strchr


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH] block/curl: use strlen instead of strchr
Date: Mon, 1 Jul 2024 09:34:55 +0300
User-agent: Mozilla Thunderbird

On 29.06.24 09:20, Michael Tokarev wrote:
On 6/28/24 08:49, Vladimir Sementsov-Ogievskiy wrote:
We already know where colon is, so no reason to search for it. Also,
avoid a code, which looks like we forget to check return value of
strchr() to NULL.

Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---

This replaces my patch
   [PATCH] block/curl: explicitly assert that strchr returns non-NULL value
Supersedes: <20240627153059.589070-1-vsementsov@yandex-team.ru>

  block/curl.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/curl.c b/block/curl.c
index 419f7c89ef..d03bfe4817 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -219,7 +219,7 @@ static size_t curl_header_cb(void *ptr, size_t size, size_t 
nmemb, void *opaque)
          && g_ascii_strncasecmp(header, accept_ranges,
                                 strlen(accept_ranges)) == 0) {
-        char *p = strchr(header, ':') + 1;
+        char *p = header + strlen(accept_ranges);
          /* Skip whitespace between the header name and value. */
          while (p < end && *p && g_ascii_isspace(*p)) {

Heck.  All these strlen()s look ugly, especially in the
loop iterations..

I expect that strlen of string constant is calculated in compilation time.

My aim was to fix Coverity complain (I don't see this complain in public qemu 
coverity project, that's why I don't specify CID in commit message), not to 
rewrite the whole function. So I'd prefer Kevein's suggesting which is both 
minimal and makes the code obviously correct.. The only simpler thing is to 
mark the problem false-positive in Coverity.

--
Best regards,
Vladimir




reply via email to

[Prev in Thread] Current Thread [Next in Thread]