1
0
mirror of https://github.com/libssh2/libssh2.git synced 2026-10-24 03:48:58 +03:00
Files
libssh2/example
Viktor Szakats 165a9c3bee example/ssh2: replace GCC silencer pragma with a simpler workaround
As of gcc-16, this still causes a false positive:
```
example/ssh2.c: In function 'main':
example/ssh2.c:215:34: error: '__builtin_snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
  215 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                  ^~~~~~~
example/ssh2.c:215:40: note: format string is defined here
  215 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                        ^
example/ssh2.c:215:13: note: '__builtin_snprintf' output 17 or more bytes (assuming 18) into a destination of size 17
  215 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |             ^~~~~~~~
example/ssh2.c:216:34: error: '__builtin_snprintf' output may be truncated before the last format character [-Werror=format-truncation=]
  216 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                  ^~~~~~~
example/ssh2.c:216:40: note: format string is defined here
  216 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                        ^
example/ssh2.c:216:13: note: '__builtin_snprintf' output 13 or more bytes (assuming 14) into a destination of size 13
  216 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |             ^~~~~~~~
```

By bumping the allocated buffers by one byte, the above disappears, but
remains in gcc-13. Fix by bumping buffer by one more byte.
```
example/ssh2.c: In function ‘main’:
example/ssh2.c:228:40: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  228 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |                                        ^
example/ssh2.c:228:13: note: ‘snprintf’ output 3 or more bytes (assuming 4) into a destination of size 3
  228 |             snprintf(fn1, fn1sz, "%s/%s", h, pubkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
example/ssh2.c:229:40: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  229 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |                                        ^
example/ssh2.c:229:13: note: ‘snprintf’ output 3 or more bytes (assuming 4) into a destination of size 3
  229 |             snprintf(fn2, fn2sz, "%s/%s", h, privkey);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/27890978881/job/82534253967#step:24:67

Closes #2100
2026-06-21 12:57:00 +02:00
..