Subject: bug#55895: [PATCH] maint: Fix ptr_align signature to silence -Wmaybe-uninitialized

From: Anders Kaseorg <[email-masked]>
Date: Fri, 10 Jun 2022 18:24:15 -0400 (EDT)

ptr_align is always called with a pointer to uninitialized memory, so
it does not make sense for that pointer to be const.  This change
avoids -Wmaybe-uninitialized warnings from GCC 11.

Signed-off-by: Anders Kaseorg <[email-masked]>
---

Some of the warnings from GCC 11.3.0 without this patch:

  CC       src/cksum-digest.o
src/digest.c: In function 'digest_check':
src/digest.c:1036:31: error: 'bin_buffer_unaligned' may be used uninitialized [-Werror=maybe-uninitialized]
 1036 |   unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/digest.c:24:
src/system.h:493:1: note: by argument 1 of type 'const void *' to 'ptr_align' declared here
  493 | ptr_align (void const *ptr, size_t alignment)
      | ^~~~~~~~~
src/digest.c:1034:17: note: 'bin_buffer_unaligned' declared here
 1034 |   unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN];
      |                 ^~~~~~~~~~~~~~~~~~~~
src/digest.c: In function 'main':
src/digest.c:1247:31: error: 'bin_buffer_unaligned' may be used uninitialized [-Werror=maybe-uninitialized]
 1247 |   unsigned char *bin_buffer = ptr_align (bin_buffer_unaligned, DIGEST_ALIGN);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/digest.c:24:
src/system.h:493:1: note: by argument 1 of type 'const void *' to 'ptr_align' declared here
  493 | ptr_align (void const *ptr, size_t alignment)
      | ^~~~~~~~~
src/digest.c:1245:17: note: 'bin_buffer_unaligned' declared here
 1245 |   unsigned char bin_buffer_unaligned[DIGEST_BIN_BYTES + DIGEST_ALIGN];
      |                 ^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:20574: src/cksum-digest.o] Error 1

 src/system.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/system.h b/src/system.h
index 0c5c9b900..120fd15e4 100644
--- a/src/system.h
+++ b/src/system.h
@@ -490,7 +490,7 @@ lcm (size_t u, size_t v)
    locations.  */
 
 static inline void *
-ptr_align (void const *ptr, size_t alignment)
+ptr_align (void *ptr, size_t alignment)
 {
   char const *p0 = ptr;
   char const *p1 = p0 + alignment - 1;
-- 
2.36.1