]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
clang-tidy: avoid assigments in `if` expressions
authorViktor Szakats <commit@vsz.me>
Tue, 7 Apr 2026 13:40:18 +0000 (15:40 +0200)
committerViktor Szakats <commit@vsz.me>
Tue, 7 Apr 2026 14:57:46 +0000 (16:57 +0200)
Also enable check in clang-tidy.

Cherry-picked from #20794

Closes #21256

.clang-tidy.yml
lib/vtls/gtls.c
lib/vtls/x509asn1.c

index d12c0458de61d915d5ff898b24e14ea61a5f9511..411bc70002f610048ace4f06d233269304aea97b 100644 (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
index 24ff85e25966b53f0bfbb989a64112aed2a96554..97ac2c8bcfd85a4e0f76e93d8bb59dc74cc9306a 100644 (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);
index b430c74704db439553b6cbab80d51c8801678901..316a2f21c15dddf2dd605ffce1f3f8fcbb2da243 100644 (file)
@@ -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. */