util: minor refactor _mesa_sha1_print()
authorMihai Preda <mhpreda@gmail.com>
Mon, 14 Nov 2022 17:58:13 +0000 (19:58 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 7 Dec 2022 12:59:33 +0000 (12:59 +0000)
should not change the output; avoids an additional printf()
for the separator.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19570>

src/util/mesa-sha1.c

index 701ba8a..bdca123 100644 (file)
@@ -27,6 +27,7 @@
 #include "sha1/sha1.h"
 #include "mesa-sha1.h"
 #include <string.h>
+#include <inttypes.h>
 
 void
 _mesa_sha1_compute(const void *data, size_t size, unsigned char result[20])
@@ -83,9 +84,7 @@ _mesa_sha1_print(FILE *f, const uint8_t sha1[SHA1_DIGEST_LENGTH])
    sha1_to_uint32(sha1, u32);
 
    for (unsigned i = 0; i < SHA1_DIGEST_LENGTH32; i++) {
-      fprintf(f, "0x%08x", u32[i]);
-      if (i < SHA1_DIGEST_LENGTH32 - 1)
-         fprintf(f, ", ");
+      fprintf(f, i ? ", 0x%08" PRIx32 : "0x%08" PRIx32, u32[i]);
    }
 }