Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the test fixture helper srcdir_path() to stop using dynamic allocations and instead build $srcdir/<file> into fixed-size static buffers, primarily to avoid GCC -Wformat-truncate issues seen in unity builds.
Changes:
- Replace dynamically allocated path buffers with
static char filepath[32][256]insidesrcdir_path(). - Remove the now-unneeded
srcdir_path_free()and its call fromstop_session_fixture(). - Add explicit
snprintf-length checking and abort on overflow.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This time without using `MAXPATHLEN`, which is missing from GNU Hurd. Nor using other constants, and 256 bytes on all platforms. Dynamic allocations almost looked good after good summer day of hair pulling, until I ran gcc-16, gcc-15, gcc-14 locally, in unity mode, where all 3 fell over with various bogus `-Wformat-truncate` false positives. This isn't worth all this effort. Ref: https://darnassus.sceen.net/~hurd-web/faq/foo_max/ Follow-up to 3f6481b1a870636d9bb19988ed61fff1f6877547 libssh2#2102 Follow-up to aae3776 libssh2#2089 Follow-up to 12427f4 libssh2#1415 Fixing: gcc-14, gcc-15: ``` tests/session_fixture.c: In function 'srcdir_path': tests/session_fixture.c:276:46: error: '%s' directive output may be truncated writing likely 1 or more bytes into a region of size between 0 and 1 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ In file included from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:7: tests/session_fixture.c:276:50: note: format string is defined here 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ tests/session_fixture.c:276:46: note: assuming directive output of 1 byte 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ src/libssh2_priv.h:151:23: note: '__builtin_snprintf' output 2 or more bytes (assuming 4) into a destination of size 2 151 | #define ssh2_snprintf snprintf | ^~~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ``` gcc-16: ``` tests/session_fixture.c: In function 'srcdir_path': tests/session_fixture.c:276:46: error: '%s' directive output may be truncated writing up to 8192 bytes into a region of size 2 [-Werror=format-truncation=] 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ In file included from bld/tests/CMakeFiles/runner.dir/Unity/unity_0_c.c:7: tests/session_fixture.c:276:47: note: format string is defined here 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~ src/libssh2_priv.h:151:23: note: '__builtin_snprintf' output between 2 and 16386 bytes into a destination of size 2 151 | #define ssh2_snprintf snprintf | ^~~~~~~~ tests/session_fixture.c:276:5: note: in expansion of macro 'ssh2_snprintf' 276 | ssh2_snprintf(filepath[curpath], buflen, "%s/%s", srcdir, file); | ^~~~~~~~~~~~~ ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This time without using
MAXPATHLEN, which is missing from GNU Hurd.Nor using other constants, but fixed 256 bytes on all platforms.
Dynamic allocations almost looked good after good summer day of hair
pulling, until I ran gcc-16, gcc-15, gcc-14 locally, in unity mode,
where all 3 fell over with
-Wformat-truncatefalse positives. Thisisn't worth all this amount of hassle.
(It also fails in CI. What confused me is the last push only triggered
AppVeyor CI and it went green. What a mess.)
Ref: https://darnassus.sceen.net/~hurd-web/faq/foo_max/
Follow-up to 4cecccd #2102
Follow-up to aae3776 #2089
Follow-up to 12427f4 #1415
Fixing:
gcc-13 (in CI):
https://github.com/libssh2/libssh2/actions/runs/27913275531/job/82594004458
gcc-14, gcc-15:
gcc-16: