]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libbacktrace: avoid -Wpointer-arith errors
authorIan Lance Taylor <iant@golang.org>
Mon, 5 Aug 2024 23:46:03 +0000 (16:46 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 5 Aug 2024 23:46:03 +0000 (16:46 -0700)
Based on patch from Kirill Müller.

* configure.ac (ACX_PROG_CC_WARNING_OPTS): Add -Wpointer-arith.
* pecoff.c (coff_add): Cast void pointers.
* xcoff.c (xcoff_add): Likewise.
* configure: Regenerate.

libbacktrace/configure
libbacktrace/configure.ac
libbacktrace/pecoff.c
libbacktrace/xcoff.c

index fe0bb2083eb169a7a632151dff1af80eb54f55d4..db491a782349698a324eb726067d5e182d1ebe6b 100755 (executable)
@@ -12385,7 +12385,8 @@ save_CFLAGS="$CFLAGS"
 for real_option in -W -Wall -Wwrite-strings -Wstrict-prototypes \
                          -Wmissing-prototypes -Wold-style-definition \
                          -Wmissing-format-attribute -Wcast-qual \
-                         -Wno-attributes -Wno-unknown-attributes; do
+                         -Wno-attributes -Wno-unknown-attributes \
+                         -Wpointer-arith; do
   # Do the check with the no- prefix removed since gcc silently
   # accepts any -Wno-* option on purpose
   case $real_option in
index bfd7f35d2d2b4c58a259210be8e56945e006ead2..69eb2023677a61ac7202199323b938329e24cfeb 100644 (file)
@@ -145,7 +145,8 @@ AC_SUBST(EXTRA_FLAGS)
 ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \
                          -Wmissing-prototypes -Wold-style-definition \
                          -Wmissing-format-attribute -Wcast-qual \
-                         -Wno-attributes -Wno-unknown-attributes],
+                         -Wno-attributes -Wno-unknown-attributes \
+                         -Wpointer-arith],
                          [WARN_FLAGS])
 
 AC_ARG_ENABLE([werror],
index ccd5ccbce2ce3db8cda636b2df169895dbca715e..15a73ff0b2aa4e850cad2b67f1324e7732dbc31f 100644 (file)
@@ -704,7 +704,7 @@ coff_add (struct backtrace_state *state, int descriptor,
       magic_ok = memcmp (magic, "PE\0", 4) == 0;
       fhdr_off += 4;
 
-      memcpy (&fhdr, fhdr_view.data + 4, sizeof fhdr);
+      memcpy (&fhdr, (const unsigned char *) fhdr_view.data + 4, sizeof fhdr);
     }
   else
     {
@@ -738,7 +738,7 @@ coff_add (struct backtrace_state *state, int descriptor,
   sects_view_valid = 1;
   opt_hdr = (const b_coff_optional_header *) sects_view.data;
   sects = (const b_coff_section_header *)
-    (sects_view.data + fhdr.size_of_optional_header);
+    ((const unsigned char *) sects_view.data + fhdr.size_of_optional_header);
 
   is_64 = 0;
   memset (&image_base, 0, sizeof image_base);
@@ -781,7 +781,8 @@ coff_add (struct backtrace_state *state, int descriptor,
        goto fail;
       syms_view_valid = 1;
 
-      str_size = coff_read4 (syms_view.data + syms_size);
+      str_size = coff_read4 ((const unsigned char *) syms_view.data
+                            + syms_size);
 
       str_off = syms_off + syms_size;
 
index 01443c48401b9fde34aad37bf961bee4721d3de3..84ce07b8e2ca701f4696ed7dca34d63de6bb22d7 100644 (file)
@@ -1203,7 +1203,9 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset,
        goto fail;
       syms_view_valid = 1;
 
-      memcpy (&str_size, syms_view.data + syms_size, 4);
+      memcpy (&str_size,
+             (const unsigned char *) syms_view.data + syms_size,
+             4);
 
       str_off = fhdr.f_symptr + syms_size;