clang-tidy: avoid assigments in `if` expressions
No binary (build failed)
—
(log yok)
| @@ -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 | |
| @@ -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); | |
| @@ -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. */ | |