From 7456e3ce3874ed99807a1394011c4b0c6e2ecaa0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 13 Feb 2005 23:10:45 +0000 Subject: [PATCH] Conform to the documented interface by null terminating argument lists! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20167 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-ld/llvm-ld.cpp | 3 +++ tools/llvmc/CompilerDriver.cpp | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index f8287f8e8d4..f19c0790298 100644 --- a/tools/llvm-ld/llvm-ld.cpp +++ b/tools/llvm-ld/llvm-ld.cpp @@ -225,6 +225,7 @@ static int GenerateAssembly(const std::string &OutputFilename, args.push_back( "-o"); args.push_back( OutputFilename.c_str() ); args.push_back( InputFilename.c_str() ); + args.push_back(0); return sys::Program::ExecuteAndWait(llc,&args[0]); } @@ -241,6 +242,7 @@ static int GenerateCFile(const std::string &OutputFile, args.push_back( "-o"); args.push_back( OutputFile.c_str() ); args.push_back( InputFile.c_str() ); + args.push_back(0); return sys::Program::ExecuteAndWait(llc, &args[0]); } @@ -300,6 +302,7 @@ static int GenerateNative(const std::string &OutputFilename, args.push_back("-l"); args.push_back(Libraries[index].c_str()); } + args.push_back(0); // Run the compiler to assembly and link together the program. return sys::Program::ExecuteAndWait(gcc, &args[0], (const char**)clean_env); diff --git a/tools/llvmc/CompilerDriver.cpp b/tools/llvmc/CompilerDriver.cpp index 6846fbc62e8..6d609c52aa6 100644 --- a/tools/llvmc/CompilerDriver.cpp +++ b/tools/llvmc/CompilerDriver.cpp @@ -394,22 +394,20 @@ private: // Invoke the program const char** Args = (const char**) - alloca(sizeof(const char*)*action->args.size()); - for (unsigned i = 0; i != action->args.size(); ++i) { + alloca(sizeof(const char*)*(action->args.size()+1)); + for (unsigned i = 0; i != action->args.size(); ++i) Args[i] = action->args[i].c_str(); - } + Args[action->args.size()] = 0; // null terminate list. if (isSet(TIME_ACTIONS_FLAG)) { Timer timer(action->program.toString()); timer.startTimer(); - int resultCode = - sys::Program::ExecuteAndWait(action->program,Args); + int resultCode = sys::Program::ExecuteAndWait(action->program, Args); timer.stopTimer(); timer.print(timer,std::cerr); return resultCode == 0; } else - return 0 == - sys::Program::ExecuteAndWait(action->program, Args); + return 0 == sys::Program::ExecuteAndWait(action->program, Args); } return true; } -- 2.34.1