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-diagnostic-nullability-extension
- bugprone-assert-side-effect
- bugprone-assignment-in-if-condition
- bugprone-chained-comparison
- bugprone-dynamic-static-initializers
- bugprone-macro-parentheses

View File

@ -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);

View File

@ -160,7 +160,9 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem,
b = (unsigned char)*beg++;
if(!(b & 0x80))
len = b;
else if(!(b &= 0x7F)) {
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)
@ -187,6 +189,7 @@ static const char *getASN1Element_(struct Curl_asn1Element *elem,
len = (len << 8) | (unsigned char) *beg++;
} while(--b);
}
}
if(len > (size_t)(end - beg))
return NULL; /* Element data does not fit in source. */
elem->beg = beg;