You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MAXPATHLEN has been in use since 54bef4c (2018-03-21), released in 1.9.0. I'm curious why this didn't come up earlier. Could be a header that I deleted recently (though the report says that not offering this macro is intentional in hurd), or tests were not built earlier?
diff --git a/tests/session_fixture.c b/tests/session_fixture.c
index 3bb9da2..caeabfc 100644
--- a/tests/session_fixture.c+++ b/tests/session_fixture.c@@ -225,11 +225,7 @@ void stop_session_fixture(void)
#define NUMPATHS 32
const char *srcdir_path(const char *file)
{
-#ifdef WIN32- static char filepath[NUMPATHS][_MAX_PATH];-#else- static char filepath[NUMPATHS][MAXPATHLEN];-#endif+ static char *filepath[NUMPATHS];
static int curpath;
char *p = getenv("srcdir");
if(curpath >= NUMPATHS) {
@@ -237,16 +233,14 @@ const char *srcdir_path(const char *file)
}
assert(curpath < NUMPATHS);
if(p) {
- /* Ensure the final string is nul-terminated on Windows */- filepath[curpath][sizeof(filepath[0]) - 1] = 0;- snprintf(filepath[curpath], sizeof(filepath[0]) - 1, "%s/%s",- p, file);+ int len = snprintf(NULL, 0, "%s/%s", p, file);+ filepath[curpath] = malloc(len + 1);+ snprintf(filepath[curpath], len + 1, "%s/%s", p, file);
}
else {
- /* Ensure the final string is nul-terminated on Windows */- filepath[curpath][sizeof(filepath[0]) - 1] = 0;- snprintf(filepath[curpath], sizeof(filepath[0]) - 1, "%s",- file);+ int len = snprintf(NULL, 0, "%s", file);+ filepath[curpath] = malloc(len + 1);+ snprintf(filepath[curpath], len + 1, "%s", file);
}
return filepath[curpath++];
Also update the comment:
diff --git a/tests/session_fixture.c b/tests/session_fixture.c
index b7cac1a7..3060f4e4 100644
--- a/tests/session_fixture.c+++ b/tests/session_fixture.c@@ -245,8 +245,7 @@ void stop_session_fixture(void)
/* Return a static string that contains a file path relative to the srcdir
- * variable, if found. It does so in a way that avoids leaking memory by using- * a fixed number of static buffers.+ * variable, if found.
*/
#define NUMPATHS 32
const char *srcdir_path(const char *file)
Activity
vszakats commentedon Jun 26, 2024
MAXPATHLENhas been in use since 54bef4c (2018-03-21), released in 1.9.0. I'm curious why this didn't come up earlier. Could be a header that I deleted recently (though the report says that not offering this macro is intentional in hurd), or tests were not built earlier?Either way, the patch posted by Mattias Ellert to the report looks like a good solution:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1068076#15
Also update the comment:
Would you like to open a PR for that?
babelouest commentedon Jun 26, 2024
If you're ok with the patch then I can make a PR with pleasure.
Although the
mallocinfilepath[curpath] = malloc(len + 1);should be free afterwards.vszakats commentedon Jun 26, 2024
Thanks, I think the patch is good. I agree to free the pointers when appropriate.
Update srcdir_path to avoid using MAXPATHLEN, wich is not present in …
babelouest commentedon Jun 26, 2024
I've updated the patch to free allocated chars and made the PR #1415
Although, I wasn't able to test the patch with valgrind to make sure all the allocated data is cleaned. Do you have a method to test memory leaks?
tests: avoid using `MAXPATHLEN`, for portability
tests: avoid using `MAXPATHLEN`, for portability