Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build warnings on lib/posix/options/env.c #72555

Closed
aescolar opened this issue May 10, 2024 · 0 comments · Fixed by #72554
Closed

Build warnings on lib/posix/options/env.c #72555

aescolar opened this issue May 10, 2024 · 0 comments · Fixed by #72554
Assignees
Labels
area: POSIX POSIX API Library bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@aescolar
Copy link
Member

Describe the bug
Depending on compile optimizations settings, lib/posix/options/env.c builds with warnings with default compiler settings.

To Reproduce
Steps to reproduce the behavior:

  1. mkdir build; cd build
  2. cmake -GNinja -DBOARD=nrf5340dk/nrf5340/cpuapp ../samples/posix/env/ -DCONFIG_SPEED_OPTIMIZATIONS=y
  3. ninja
  4. See error

Expected behavior
No build warnings

Impact
Either annoyance for users, or broken CI when this is triggered in CI (it is triggered downstream with some samples).

Logs and console output

../../../../../../../zephyr/lib/posix/options/env.c: In function 'getenv_r':
../../../../../../../zephyr/lib/posix/options/env.c:109:17: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-truncation]
  109 |                 strncpy(buf, val, vsize);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../zephyr/lib/posix/options/env.c:104:25: note: length computed here
  104 |                 vsize = strlen(val) + 1;
      |                         ^~~~~~~~~~~
../../../../../../../zephyr/lib/posix/options/env.c: In function 'setenv':
../../../../../../../zephyr/lib/posix/options/env.c:191:17: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
  191 |                 strncpy(environ[ret], name, nsize);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../zephyr/lib/posix/options/env.c:128:51: note: length computed here
  128 |         const size_t nsize = (name == NULL) ? 0 : strlen(name);
      |                                                   ^~~~~~~~~~~~
cc1: all warnings being treated as errors

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK 0.16.5-1
  • Commit SHA or Version used: Main as of today a495fd9
@aescolar aescolar added the bug The issue is a bug, or the PR is fixing a bug label May 10, 2024
@aescolar aescolar added priority: low Low impact/importance bug area: POSIX POSIX API Library labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: POSIX POSIX API Library bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants