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

i3-input: Avoid compiler warning #5480

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

orestisfl
Copy link
Member

Also updates the function to use proper types, const and style.

The warning:

../i3/i3-input/main.c: In function ‘finish_input’: ../i3/i3-input/main.c:187:13: warning: ‘__builtin_strncat’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
  187 |             strncat(dest, command, inputlen);
      |             ^
../i3/i3-input/main.c:175:20: note: length computed here
  175 |     int inputlen = strlen(command);

Which is triggered because gcc thinks it's bad that input_len (the length of the source in the copy) is used instead of a length that is inside the limits of the allocated size for the destination. However, in practice, full_len is always than input_len.

Also updates the function to use proper types, const and style.

The warning:

../i3/i3-input/main.c: In function ‘finish_input’:
../i3/i3-input/main.c:187:13: warning: ‘__builtin_strncat’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
  187 |             strncat(dest, command, inputlen);
      |             ^
../i3/i3-input/main.c:175:20: note: length computed here
  175 |     int inputlen = strlen(command);

Which is triggered because gcc thinks it's bad that `input_len` (the
length of the source in the copy) is used instead of a length that is
inside the limits of the allocated size for the destination. However, in
practice, `full_len` is always than `input_len`.
@stapelberg stapelberg merged commit fae2b63 into i3:next Apr 22, 2023
3 checks passed
@orestisfl orestisfl deleted the i3-input-avoid-compiler-warning branch April 22, 2023 17:36
jbenden pushed a commit to jbenden/i3 that referenced this pull request Jun 7, 2023
Also updates the function to use proper types, const and style.

The warning:

../i3/i3-input/main.c: In function ‘finish_input’:
../i3/i3-input/main.c:187:13: warning: ‘__builtin_strncat’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
  187 |             strncat(dest, command, inputlen);
      |             ^
../i3/i3-input/main.c:175:20: note: length computed here
  175 |     int inputlen = strlen(command);

Which is triggered because gcc thinks it's bad that `input_len` (the
length of the source in the copy) is used instead of a length that is
inside the limits of the allocated size for the destination. However, in
practice, `full_len` is always than `input_len`.
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

Successfully merging this pull request may close these issues.

None yet

2 participants