From efa3da5593117eab5209c9197cad5ca42213c12e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 13 Oct 2006 00:06:24 +0000 Subject: [PATCH] avoid a ctor/dtor issue with the ProgramName global. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30925 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/CommandLine.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index cd903126f5b..39d388cbeae 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -57,8 +57,9 @@ void parser::anchor() {} //===----------------------------------------------------------------------===// -// Globals for name and overview of program -static std::string ProgramName = ""; +// Globals for name and overview of program. Program name is not a string to +// avoid static ctor/dtor issues. +static char ProgramName[80] = ""; static const char *ProgramOverview = 0; // This collects additional help to be printed. @@ -303,7 +304,12 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, "No options specified, or ParseCommandLineOptions called more" " than once!"); sys::Path progname(argv[0]); - ProgramName = sys::Path(argv[0]).getLast(); + + // Copy the program name into ProgName, making sure not to overflow it. + std::string ProgName = sys::Path(argv[0]).getLast(); + if (ProgName.size() > 79) ProgName.resize(79); + strcpy(ProgramName, ProgName.c_str()); + ProgramOverview = Overview; bool ErrorParsing = false; -- 2.11.0