From 9ba9f3ee7bf1b0e6b211425a6c495f5dddf8c2d0 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 18 Mar 2023 00:17:54 -0700 Subject: [PATCH] Add and use SHA1_HASH_STRING_LEN constant --- include/wimlib/sha1.h | 3 ++- src/blob_table.c | 2 +- src/inode.c | 2 +- src/resource.c | 4 ++-- src/sha1.c | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/wimlib/sha1.h b/include/wimlib/sha1.h index e8167faf..e1def3d9 100644 --- a/include/wimlib/sha1.h +++ b/include/wimlib/sha1.h @@ -37,8 +37,9 @@ extern const u8 zero_hash[SHA1_HASH_SIZE]; +#define SHA1_HASH_STRING_LEN (2 * SHA1_HASH_SIZE + 1) extern void -sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_SIZE * 2 + 1]); +sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_STRING_LEN]); static inline void copy_hash(u8 dest[SHA1_HASH_SIZE], const u8 src[SHA1_HASH_SIZE]) diff --git a/src/blob_table.c b/src/blob_table.c index 5c26e894..cec5b498 100644 --- a/src/blob_table.c +++ b/src/blob_table.c @@ -1275,7 +1275,7 @@ after_blob_hashed(struct blob_descriptor *blob, * blob (from a stream) to point to the duplicate. The caller * is responsible for freeing @blob if needed. */ if (duplicate_blob->size != blob->size) { - tchar hash_str[SHA1_HASH_SIZE * 2 + 1]; + tchar hash_str[SHA1_HASH_STRING_LEN]; sprint_hash(blob->hash, hash_str); WARNING("SHA-1 collision at \"%"TS"\"\n" diff --git a/src/inode.c b/src/inode.c index 68e88c05..7699e9bf 100644 --- a/src/inode.c +++ b/src/inode.c @@ -485,7 +485,7 @@ int blob_not_found_error(const struct wim_inode *inode, const u8 *hash) { if (wimlib_print_errors) { - tchar hashstr[SHA1_HASH_SIZE * 2 + 1]; + tchar hashstr[SHA1_HASH_STRING_LEN]; sprint_hash(hash, hashstr); diff --git a/src/resource.c b/src/resource.c index dd0d2edd..afba8774 100644 --- a/src/resource.c +++ b/src/resource.c @@ -1015,8 +1015,8 @@ static int report_sha1_mismatch(struct blob_descriptor *blob, const u8 actual_hash[SHA1_HASH_SIZE], bool recover_data) { - tchar expected_hashstr[SHA1_HASH_SIZE * 2 + 1]; - tchar actual_hashstr[SHA1_HASH_SIZE * 2 + 1]; + tchar expected_hashstr[SHA1_HASH_STRING_LEN]; + tchar actual_hashstr[SHA1_HASH_STRING_LEN]; wimlib_assert(blob->blob_location != BLOB_NONEXISTENT); wimlib_assert(blob->blob_location != BLOB_IN_ATTACHED_BUFFER); diff --git a/src/sha1.c b/src/sha1.c index 58f60dd7..b3062389 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -43,7 +43,7 @@ const u8 zero_hash[20]; * The output buffer must be at least 41 characters. */ void -sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_SIZE * 2 + 1]) +sprint_hash(const u8 hash[SHA1_HASH_SIZE], tchar strbuf[SHA1_HASH_STRING_LEN]) { int i; u8 high, low; -- 2.43.0