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

Warnings found when building with new-ish C compilers #263

Open
daviesrob opened this issue Aug 1, 2022 · 0 comments
Open

Warnings found when building with new-ish C compilers #263

daviesrob opened this issue Aug 1, 2022 · 0 comments

Comments

@daviesrob
Copy link

While attempting some builds with recent compilers I got the following warnings:

clang 13 doesn't like this line:

src/write.c:279:11: warning: explicitly assigning value of variable of type 'int' to itself [-Wself-assign]
    flags = flags;
    ~~~~~ ^ ~~~~~

gcc 12.1, on the other hand has no trouble with assigning a variable to itself, but doesn't like the use of strncpy() in src/query.c prepare_obj_list and prepare_obj_repl_list:

src/query.c: In function ‘prepare_obj_list’:
src/query.c:189:5: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
  189 |     strncpy(path1, path, len);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
src/query.c:182:18: note: length computed here
  182 |     size_t len = strlen(path) + 1;
      |                  ^~~~~~~~~~~~
src/query.c:190:5: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
  190 |     strncpy(path2, path, len);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
src/query.c:182:18: note: length computed here
  182 |     size_t len = strlen(path) + 1;
      |                  ^~~~~~~~~~~~
src/query.c: In function ‘prepare_obj_repl_list’:
src/query.c:285:5: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
  285 |     strncpy(path1, path, len);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
src/query.c:278:18: note: length computed here
  278 |     size_t len = strlen(path) + 1;
      |                  ^~~~~~~~~~~~
src/query.c:286:5: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-truncation]
  286 |     strncpy(path2, path, len);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
src/query.c:278:18: note: length computed here
  278 |     size_t len = strlen(path) + 1;
      |                  ^~~~~~~~~~~~

These are arguably a false positive, but there isn't much sign of that being fixed. In both cases it looks like it would be easier to use strdup() though, which would fix the warnings and simplify the code a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant