clang-tidy: avoid assigments in if expressions

Also enable check in clang-tidy.

Cherry-picked from #20794

Closes #21256
This commit is contained in:
Viktor Szakats 2026-04-07 15:40:18 +02:00
parent 3536730f33
commit d3dc5dbc87
No known key found for this signature in database
3 changed files with 38 additions and 29 deletions

View File

@ -13,6 +13,7 @@ Checks:
- -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling - -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling
- -clang-diagnostic-nullability-extension - -clang-diagnostic-nullability-extension
- bugprone-assert-side-effect - bugprone-assert-side-effect
- bugprone-assignment-in-if-condition
- bugprone-chained-comparison - bugprone-chained-comparison
- bugprone-dynamic-static-initializers - bugprone-dynamic-static-initializers
- bugprone-macro-parentheses - bugprone-macro-parentheses

View File

@ -203,10 +203,15 @@ static gnutls_datum_t load_file(const char *file)
f = curlx_fopen(file, "rb"); f = curlx_fopen(file, "rb");
if(!f) if(!f)
return loaded_file; return loaded_file;
if(fseek(f, 0, SEEK_END) != 0 || if(fseek(f, 0, SEEK_END) != 0)
(filelen = ftell(f)) < 0 || goto out;
fseek(f, 0, SEEK_SET) != 0 || filelen = ftell(f);
!(ptr = curlx_malloc((size_t)filelen))) if(filelen < 0)
goto out;
if(fseek(f, 0, SEEK_SET) != 0)
goto out;
ptr = curlx_malloc((size_t)filelen);
if(!ptr)
goto out; goto out;
if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) {
curlx_free(ptr); curlx_free(ptr);

View File

@ -160,7 +160,9 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem,
b = (unsigned char)*beg++; b = (unsigned char)*beg++;
if(!(b & 0x80)) if(!(b & 0x80))
len = b; len = b;
else if(!(b &= 0x7F)) { else {
b &= 0x7F;
if(!b) {
/* Unspecified length. Since we have all the data, we can determine the /* Unspecified length. Since we have all the data, we can determine the
effective length by skipping element until an end element is found. */ effective length by skipping element until an end element is found. */
if(!elem->constructed) if(!elem->constructed)
@ -187,6 +189,7 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem,
len = (len << 8) | (unsigned char) *beg++; len = (len << 8) | (unsigned char) *beg++;
} while(--b); } while(--b);
} }
}
if(len > (size_t)(end - beg)) if(len > (size_t)(end - beg))
return NULL; /* Element data does not fit in source. */ return NULL; /* Element data does not fit in source. */
elem->beg = beg; elem->beg = beg;