Skip to content

Commit 0a08926

Browse files
authored
Merge pull request #230 from tsoding/next-release
v3.8.2 - Fix the broken type safety of nob_cmd_append()
2 parents 0ce166a + d22059e commit 0a08926

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

nob.h

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* nob - v3.8.1 - Public Domain - https://github.com/tsoding/nob.h
1+
/* nob - v3.8.2 - Public Domain - https://github.com/tsoding/nob.h
22
33
This library is the next generation of the [NoBuild](https://github.com/tsoding/nobuild) idea.
44
@@ -660,9 +660,19 @@ NOBDEF void nob_cmd_render(Nob_Cmd cmd, Nob_String_Builder *render);
660660
#define NOB_CLIT(type) (type)
661661
#endif
662662

663-
NOBDEF void nob__cmd_append(Nob_Cmd *cmd, ...);
664-
#define nob_cmd_append(cmd, ...) \
665-
nob__cmd_append(cmd, __VA_ARGS__, (const char*)-1)
663+
NOBDEF void nob__cmd_append(Nob_Cmd *cmd, size_t n, const char **args);
664+
#if defined(__cplusplus)
665+
template <typename... Args>
666+
static inline void nob__cpp_cmd_append_wrapper(Nob_Cmd *cmd, Args... strs)
667+
{
668+
const char* args[] = { strs... };
669+
nob__cmd_append(cmd, sizeof(args)/sizeof(args[0]), args);
670+
}
671+
#define nob_cmd_append(cmd, ...) nob__cpp_cmd_append_wrapper(cmd, __VA_ARGS__)
672+
#else
673+
#define nob_cmd_append(cmd, ...) \
674+
nob__cmd_append(cmd, sizeof((const char*[]){__VA_ARGS__})/sizeof(const char*), (const char*[]){__VA_ARGS__})
675+
#endif // __cplusplus
666676

667677
// TODO: nob_cmd_extend() evaluates other_cmd twice
668678
// It can be fixed by turning nob_cmd_extend() call into a statement.
@@ -959,16 +969,11 @@ static Nob_Proc nob__cmd_start_process(Nob_Cmd cmd, Nob_Fd *fdin, Nob_Fd *fdout,
959969
// Any messages with the level below nob_minimal_log_level are going to be suppressed.
960970
Nob_Log_Level nob_minimal_log_level = NOB_INFO;
961971

962-
NOBDEF void nob__cmd_append(Nob_Cmd *cmd, ...)
972+
NOBDEF void nob__cmd_append(Nob_Cmd *cmd, size_t n, const char **args)
963973
{
964-
va_list args;
965-
va_start(args, cmd);
966-
for (;;) {
967-
const char *arg = va_arg(args, const char *);
968-
if (arg == (const char*)-1) break;
969-
nob_da_append(cmd, arg);
974+
for (size_t i = 0; i < n; ++i) {
975+
nob_da_append(cmd, args[i]);
970976
}
971-
va_end(args);
972977
}
973978

974979
#ifdef _WIN32
@@ -1529,7 +1534,7 @@ static Nob_Proc nob__cmd_start_process(Nob_Cmd cmd, Nob_Fd *fdin, Nob_Fd *fdout,
15291534
// But do we actually care? It's a one off leak anyway...
15301535
Nob_Cmd cmd_null = {0};
15311536
nob_da_append_many(&cmd_null, cmd.items, cmd.count);
1532-
nob_cmd_append(&cmd_null, NULL);
1537+
nob_cmd_append(&cmd_null, (const char*)NULL);
15331538

15341539
if (execvp(cmd.items[0], (char * const*) cmd_null.items) < 0) {
15351540
nob_log(NOB_ERROR, "Could not exec child process for %s: %s", cmd.items[0], strerror(errno));
@@ -3023,6 +3028,7 @@ NOBDEF char *nob_temp_running_executable_path(void)
30233028
/*
30243029
Revision history:
30253030
3031+
3.8.2 (2026-04-01) Fix the broken type safety of nob_cmd_append() (by @aalmkainzi)
30263032
3.8.1 (2026-04-01) Fix annoying clang warning
30273033
3.8.0 (2026-03-24) Add NOB_CLIT()
30283034
Fix compliation on MSVC with /TP

0 commit comments

Comments
 (0)