Skip to content

Commit ac0b488

Browse files
committed
fix: miscellaneous minor warnigns in the test build
The -std=gnu11 change stems from the error system refactoring, where we do rely on variadic macros that may take zero arguments. This uses the ##__VA_ARGS__ gnu extension which was implict in the main library build but warned about in the tests due to the explicit -std=c11 flag. Since ##__VA_ARGS__ is supported in GCC and clang I'm relenting to use it for now; could move to C23 which has __VA_OPT__ but I'd like to stick mainly to an older C standard for now but not shy away from a few extensions.
1 parent fff42e1 commit ac0b488

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

tests/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ asdf_standard_dir = $(abs_top_srcdir)/asdf-standard
99
asdf_standard_submodule = $(asdf_standard_dir)/.git
1010
munit_dir = $(top_builddir)/tests/munit
1111
munit_submodule = $(munit_dir)/.git
12-
munit_cflags = -std=c11 -I$(top_srcdir)/tests
12+
munit_cflags = -std=gnu11 -I$(top_srcdir)/tests
1313
munit_ldflags = $(builddir)/libmunit.a
1414
submodules = $(asdf_standard_submodule) $(munit_submodule)
1515

tests/util.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ static void pioneer_setup(int fd_create, const char *pgid_file) {
237237

238238
/* Reuse the previous run directory if it is still empty. */
239239
if (try_reuse_latest(serial_str)) {
240-
(void)write(fd_create, serial_str, strlen(serial_str));
240+
if (write(fd_create, serial_str, strlen(serial_str)) < 0)
241+
goto failure;
241242
close(fd_create);
242243
return;
243244
}
@@ -249,20 +250,28 @@ static void pioneer_setup(int fd_create, const char *pgid_file) {
249250
if (n < 0 || n >= (int)sizeof(run_dir_storage))
250251
break;
251252
if (mkdir(run_dir_storage, 0777) == 0) {
252-
snprintf(serial_str, sizeof(serial_str), TEST_SERIAL_FMT, run_num);
253-
(void)write(fd_create, serial_str, strlen(serial_str));
253+
/* Use a larger buffer to avoid format-truncation: run_num is
254+
* bounded by TEST_SERIAL_MAX (1000000) so the output is always
255+
* TEST_SERIAL_LEN digits, but GCC sees the full int range. */
256+
char serial_buf[32];
257+
snprintf(serial_buf, sizeof(serial_buf), TEST_SERIAL_FMT, run_num);
258+
memcpy(serial_str, serial_buf, TEST_SERIAL_LEN + 1);
259+
if (write(fd_create, serial_str, strlen(serial_str)) < 0)
260+
goto failure;
254261
close(fd_create);
255262
char latest[PATH_MAX];
256263
snprintf(latest, sizeof(latest), TEMP_DIR "/latest");
257264
unlink(latest);
258-
symlink(serial_str, latest); /* best-effort */
265+
int rc = symlink(serial_str, latest); /* best-effort */
266+
(void)rc;
259267
return;
260268
}
261269
if (errno != EEXIST)
262270
break;
263271
}
264272

265-
/* Failed to create a run directory; clean up and fall back. */
273+
failure:
274+
/* Failed to create a run directory or write the serial; clean up. */
266275
run_dir_storage[0] = '\0';
267276
close(fd_create);
268277
unlink(pgid_file);

0 commit comments

Comments
 (0)