From 7d88d8f27c96476ce6d627822d2418edd232e32d Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 23 Feb 2019 12:00:41 +0000 Subject: discontinue use of alloca NetBSD emits: warning: Warning: reference to the libc supplied alloca(3); this most likely will not work. Please use the compiler provided version of alloca(3), by supplying the appropriate compiler flags (e.g. not -std=c89). and man 3 alloca says: Normally, gcc(1) translates calls to alloca() with inlined code. This is not done when either the -ansi, -std=c89, -std=c99, or the -std=c11 option is given and the header is not included. Otherwise, (without an -ansi or -std=c* option) the glibc version of includes and that contains the lines: #ifdef __GNUC__ #define alloca(size) __builtin_alloca (size) #endif It looks like alloca is a bad idea in modern C/C++, so we use VLAs for C and std::vector for C++. --- src/common/spawn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common/spawn.cpp') diff --git a/src/common/spawn.cpp b/src/common/spawn.cpp index e03552f8c..9a7e75d41 100644 --- a/src/common/spawn.cpp +++ b/src/common/spawn.cpp @@ -91,7 +91,7 @@ int spawn(const char *filename, const std::vector& args, bool wait) MINFO("Child exited with " << exitCode); return static_cast(exitCode); #else - char **argv = (char**)alloca(sizeof(char*) * (args.size() + 1)); + std::vector argv(args.size() + 1); for (size_t n = 0; n < args.size(); ++n) argv[n] = (char*)args[n].c_str(); argv[args.size()] = NULL; @@ -109,7 +109,7 @@ int spawn(const char *filename, const std::vector& args, bool wait) tools::closefrom(3); close(0); char *envp[] = {NULL}; - execve(filename, argv, envp); + execve(filename, argv.data(), envp); MERROR("Failed to execve: " << strerror(errno)); return -1; } -- cgit v1.2.3