Re: [hatari-devel] Compiler warnings changes

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Am Mon, 6 Nov 2023 20:40:00 +0200
schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:

> Hi Thomas,
> 
> I'm getting compiler warning from your recent zip.c change:
> -----------------------------------------------
> src/zip.c: In function ‘ZIP_GetFilesDir’:
> src/zip.c:327:17: warning: ‘strncpy’ specified bound 256 equals 
> destination size [-Wstringop-truncation]
>    327 |                 strncpy(fentries[i]->d_name, files->names[i], 
> sizeof(fentries[i]->d_name));
>        | 
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> -----------------------------------------------
> 
> As it redundantly allows one extra char (one being overwritten with 
> terminating nil) to be written by strncpy().
> 
> Are you not seeing it?

No, I don't get those, and the CI is green, too:

 https://cirrus-ci.com/build/4983829757165568

 https://gitlab.com/huth/hatari/-/pipelines/1062850068

(and at least the gitlab jobs are using -Werror)

Which compiler version / distro are you using?

> I'm not sure how important it's to avoid it though, as this is not a 
> real problem:
> -----------------------------------------------
> -               strncpy(fentries[i]->d_name, files->names[i], 
> sizeof(fentries[i]->d_name));
> +               strncpy(fentries[i]->d_name, files->names[i], 
> sizeof(fentries[i]->d_name)-1);
>                  fentries[i]->d_name[sizeof(fentries[i]->d_name) - 1] = 0;
> -----------------------------------------------

That looks like a sane fix to silence the warning, feel free to commit it!

 Thomas



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/