From: Viktor Szakats Date: Tue, 7 Apr 2026 13:40:18 +0000 (+0200) Subject: clang-tidy: avoid assigments in `if` expressions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3dc5dbc87f3047ecac73aa0e7fb190cee59eb86;p=thirdparty%2Fcurl.git clang-tidy: avoid assigments in `if` expressions Also enable check in clang-tidy. Cherry-picked from #20794 Closes #21256 --- diff --git a/.clang-tidy.yml b/.clang-tidy.yml index d12c0458de..411bc70002 100644 --- a/.clang-tidy.yml +++ b/.clang-tidy.yml @@ -13,6 +13,7 @@ Checks: - -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling - -clang-diagnostic-nullability-extension - bugprone-assert-side-effect + - bugprone-assignment-in-if-condition - bugprone-chained-comparison - bugprone-dynamic-static-initializers - bugprone-macro-parentheses diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c index 24ff85e259..97ac2c8bcf 100644 --- a/lib/vtls/gtls.c +++ b/lib/vtls/gtls.c @@ -203,10 +203,15 @@ static gnutls_datum_t load_file(const char *file) f = curlx_fopen(file, "rb"); if(!f) return loaded_file; - if(fseek(f, 0, SEEK_END) != 0 || - (filelen = ftell(f)) < 0 || - fseek(f, 0, SEEK_SET) != 0 || - !(ptr = curlx_malloc((size_t)filelen))) + if(fseek(f, 0, SEEK_END) != 0) + goto out; + filelen = ftell(f); + if(filelen < 0) + goto out; + if(fseek(f, 0, SEEK_SET) != 0) + goto out; + ptr = curlx_malloc((size_t)filelen); + if(!ptr) goto out; if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { curlx_free(ptr); diff --git a/lib/vtls/x509asn1.c b/lib/vtls/x509asn1.c index b430c74704..316a2f21c1 100644 --- a/lib/vtls/x509asn1.c +++ b/lib/vtls/x509asn1.c @@ -160,32 +160,35 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem, b = (unsigned char)*beg++; if(!(b & 0x80)) len = b; - else if(!(b &= 0x7F)) { - /* Unspecified length. Since we have all the data, we can determine the - effective length by skipping element until an end element is found. */ - if(!elem->constructed) - return NULL; - elem->beg = beg; - while(beg < end && *beg) { - beg = getASN1Element_(&lelem, beg, end, lvl + 1); - if(!beg) + else { + b &= 0x7F; + if(!b) { + /* Unspecified length. Since we have all the data, we can determine the + effective length by skipping element until an end element is found. */ + if(!elem->constructed) + return NULL; + elem->beg = beg; + while(beg < end && *beg) { + beg = getASN1Element_(&lelem, beg, end, lvl + 1); + if(!beg) + return NULL; + } + if(beg >= end) return NULL; + elem->end = beg; + return beg + 1; + } + else if((unsigned)b > (size_t)(end - beg)) + return NULL; /* Does not fit in source. */ + else { + /* Get long length. */ + len = 0; + do { + if(len & 0xFF000000L) + return NULL; /* Lengths > 32 bits are not supported. */ + len = (len << 8) | (unsigned char) *beg++; + } while(--b); } - if(beg >= end) - return NULL; - elem->end = beg; - return beg + 1; - } - else if((unsigned)b > (size_t)(end - beg)) - return NULL; /* Does not fit in source. */ - else { - /* Get long length. */ - len = 0; - do { - if(len & 0xFF000000L) - return NULL; /* Lengths > 32 bits are not supported. */ - len = (len << 8) | (unsigned char) *beg++; - } while(--b); } if(len > (size_t)(end - beg)) return NULL; /* Element data does not fit in source. */