Re: [hatari-devel] Compiler warnings changes |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Compiler warnings changes
- From: Thomas Huth <th.huth@xxxxxxxxx>
- Date: Mon, 6 Nov 2023 19:22:44 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1699298566; bh=OUvu7pEUPVrnRWH+8jazTfCs09H/OBoNqLiZgy84XAo=; h=Date:From:To:Subject:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=M2ZRItxLL6x0NwkC7cU+Sh8m0l96Tjw9CTeXdKJuYCGO4/rSIWC5LjvTkumlX4BqT eTgnpg80+LDXkazI5ekW9H8ucoi2I7PkxoBkB1v03Ac0xFfbF7D+cwfXAu9K/lGodk eViUE5mfQ3wuXo/i1SOEyIEhhqpkAErYkypvV/a9ad+pA17cj3EqNDMGuoZh9xPqBV 1Ki75Vyi0EXvfBVU7dBcgoegYq7MglQJWCb93SjEfpPRx7NtqFZyQcuB6XJMP64j2r OULLZGMmpjJWxG4a1bqp/9ZN7yXlaX4FJmWDJ9jLi3JdJHzdAaqdZZ2Xf5GmK/MXvh 9NdSv6UObYTHA==
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