diff options
author | 2022-04-09 12:03:52 -0400 | |
---|---|---|
committer | 2022-04-09 18:27:57 +0200 | |
commit | 20181974c221c84a3c857e83f4f51419ca1a8b23 (patch) | |
tree | 9607d97e2f0e5a4d75125c5740055ce4cb708126 | |
parent | Fix farsi label (diff) | |
download | sway-20181974c221c84a3c857e83f4f51419ca1a8b23.tar.gz sway-20181974c221c84a3c857e83f4f51419ca1a8b23.tar.zst sway-20181974c221c84a3c857e83f4f51419ca1a8b23.zip |
Avoid format-truncation warning
The existing code gives this error when compiled with GCC 12:
../sway/server.c: In function ‘server_init’:
../sway/server.c:217:75: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 8 [-Werror=format-truncation=]
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i);
| ^~
../sway/server.c:217:66: note: directive argument in the range [-2147483647, 32]
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i);
| ^~~~~~~~~~~~
../sway/server.c:217:17: note: ‘snprintf’ output between 10 and 20 bytes into a destination of size 16
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Because i is never negative, this is a false positive, but it is easy to
change i to unsigned to silence the error.
-rw-r--r-- | sway/server.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sway/server.c b/sway/server.c index 8de9f629..9bfcffaf 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -213,8 +213,8 @@ bool server_init(struct sway_server *server) { | |||
213 | 213 | ||
214 | // Avoid using "wayland-0" as display socket | 214 | // Avoid using "wayland-0" as display socket |
215 | char name_candidate[16]; | 215 | char name_candidate[16]; |
216 | for (int i = 1; i <= 32; ++i) { | 216 | for (unsigned int i = 1; i <= 32; ++i) { |
217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%d", i); | 217 | snprintf(name_candidate, sizeof(name_candidate), "wayland-%u", i); |
218 | if (wl_display_add_socket(server->wl_display, name_candidate) >= 0) { | 218 | if (wl_display_add_socket(server->wl_display, name_candidate) >= 0) { |
219 | server->socket = strdup(name_candidate); | 219 | server->socket = strdup(name_candidate); |
220 | break; | 220 | break; |