[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fix multiple compiler warnings when building with gcc-12



Hi Tyrel!

On 1/5/23 21:58, Tyrel Datwyler wrote:
On 12/26/22 01:54, John Paul Adrian Glaubitz wrote:
This patch series fixes a number of warnings when building powerpc-utils
with gcc-12 or newer. Since the project builds with "-Werror" by default,
these warnings will cause the build to fail.

With these patches applied, all warnings are gone when building on ppc64el,
there are two additional warnings left regarding possibly truncated strings
when building on big-endian PowerPC targets for which I will send a separate
patch set.

I ran our CI with the latest Ubuntu LTS runner which has the gcc-11 toolchain
and I see the two truncated string warnings with that toolchain.

So, these two warnings actually go away when I replace strncpy() with memcpy()
but I have to admit, I don't fully understand why that's the case.

diff --git a/src/errinjct/ioa_bus_error.c b/src/errinjct/ioa_bus_error.c
index 9d85cfa..5ee1401 100644
--- a/src/errinjct/ioa_bus_error.c
+++ b/src/errinjct/ioa_bus_error.c
@@ -204,7 +204,7 @@ static uint32_t get_config_addr_from_reg(char *devpath)
        uint32_t *be_caddr;
        uint32_t caddr = 0;
- strncpy(path, devpath, BUFSZ-5);
+       memcpy(path, devpath, BUFSZ-5);
        strcat(path, "/reg");
buf = read_file(path, NULL);
diff --git a/src/serv_config.c b/src/serv_config.c
index 00ab672..2565533 100644
--- a/src/serv_config.c
+++ b/src/serv_config.c
@@ -707,7 +707,7 @@ retrieve_value(struct service_var *var, char *buf, size_t size) {
                                byte_to_string(param[2], buf, size);
                        }
                        else {
-                               strncpy(buf, param+2, ((size>ret_size)?
+                               memcpy(buf, param+2, ((size>ret_size)?
                                        ret_size:size));
                                buf[ret_size] = '\0';
                        }

If you're fine with that change, I can post a patch to the mailing list.

Adrian

--
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer
`. `'   Physicist
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


Reply to: