Fix bugs found by clangsa

Change-Id: If4c5603eada7c95154cfd5bd3156fbe972b720ba
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/82147
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/fipsmodule/hmac/hmac.cc.inc b/crypto/fipsmodule/hmac/hmac.cc.inc
index fb0805d..9007783 100644
--- a/crypto/fipsmodule/hmac/hmac.cc.inc
+++ b/crypto/fipsmodule/hmac/hmac.cc.inc
@@ -168,7 +168,6 @@
       !EVP_MD_CTX_copy_ex(&ctx->md_ctx, &ctx->o_ctx) ||
       !EVP_DigestUpdate(&ctx->md_ctx, buf, i) ||
       !EVP_DigestFinal_ex(&ctx->md_ctx, out, out_len)) {
-    *out_len = 0;
     goto out;
   }
 
@@ -178,6 +177,8 @@
   FIPS_service_indicator_unlock_state();
   if (ret) {
     HMAC_verify_service_indicator(ctx->md);
+  } else if (out_len) {
+    *out_len = 0;
   }
   return ret;
 }
diff --git a/crypto/fipsmodule/self_check/self_check.cc.inc b/crypto/fipsmodule/self_check/self_check.cc.inc
index fc92f32..341ff58 100644
--- a/crypto/fipsmodule/self_check/self_check.cc.inc
+++ b/crypto/fipsmodule/self_check/self_check.cc.inc
@@ -696,9 +696,9 @@
   uint8_t output[EVP_MAX_MD_SIZE];
 
   unsigned output_len;
-  HMAC(EVP_sha256(), kInput, sizeof(kInput), kInput, sizeof(kInput), output,
-       &output_len);
-  return output_len == sizeof(kPlaintextHMACSHA256) &&
+  return NULL != HMAC(EVP_sha256(), kInput, sizeof(kInput), kInput,
+                      sizeof(kInput), output, &output_len) &&
+         output_len == sizeof(kPlaintextHMACSHA256) &&
          BORINGSSL_check_test(kPlaintextHMACSHA256, output,
                               sizeof(kPlaintextHMACSHA256), "HMAC-SHA-256 KAT");
 }