From 74cd0694f9b7d8b9d939d6104b0cc319753c513c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 15 Oct 2009 23:21:22 +0000 Subject: [PATCH] Use an std::vector<> instead of an array of ARG_MAX size, as ARG_MAX may not be defined everywhere. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84220 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/CIndex/CIndex.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 5e999c1003..23bbb0c0eb 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "llvm/System/Path.h" using namespace clang; @@ -293,26 +294,25 @@ CXTranslationUnit clang_createTranslationUnitFromSourceFile( const char *source_filename, int num_command_line_args, const char **command_line_args) { - // Build up the arguments for involking clang. - int argc = 0; - const char * argv[ARG_MAX]; - argv[argc++] = clangPath; - argv[argc++] = "-emit-ast"; - argv[argc++] = source_filename; - argv[argc++] = "-o"; + // Build up the arguments for involing clang. + std::vector argv; + argv.push_back(clangPath); + argv.push_back("-emit-ast"); + argv.push_back(source_filename); + argv.push_back("-o"); // Generate a temporary name for the AST file. char astTmpFile[L_tmpnam]; - argv[argc++] = tmpnam(astTmpFile); + argv.push_back(tmpnam(astTmpFile)); for (int i = num_command_line_args; i < num_command_line_args; i++) - argv[argc++] = command_line_args[i]; - argv[argc] = 0; - + argv.push_back(command_line_args[i]); + argv.push_back(NULL); + // Generate the AST file in a separate process. pid_t child_pid = fork(); if (child_pid == 0) { // Child process // Execute the command, passing the appropriate arguments. - execv(argv[0], (char *const *)argv); + execv(argv[0], (char *const *)&argv[0]); // If execv returns, it failed. assert(0 && "execv() failed"); -- 2.40.0