[llvm-commits] CVS: llvm/lib/Support/CommandLine.cpp

Chris Lattner sabre at nondot.org
Thu Oct 12 17:06:39 PDT 2006



Changes in directory llvm/lib/Support:

CommandLine.cpp updated: 1.77 -> 1.78
---
Log message:

avoid a ctor/dtor issue with the ProgramName global.


---
Diffs of the changes:  (+9 -3)

 CommandLine.cpp |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)


Index: llvm/lib/Support/CommandLine.cpp
diff -u llvm/lib/Support/CommandLine.cpp:1.77 llvm/lib/Support/CommandLine.cpp:1.78
--- llvm/lib/Support/CommandLine.cpp:1.77	Thu Oct 12 17:09:17 2006
+++ llvm/lib/Support/CommandLine.cpp	Thu Oct 12 19:06:24 2006
@@ -57,8 +57,9 @@
 
 //===----------------------------------------------------------------------===//
 
-// Globals for name and overview of program
-static std::string ProgramName = "<premain>";
+// Globals for name and overview of program.  Program name is not a string to
+// avoid static ctor/dtor issues.
+static char ProgramName[80] = "<premain>";
 static const char *ProgramOverview = 0;
 
 // This collects additional help to be printed.
@@ -303,7 +304,12 @@
          "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;
 






More information about the llvm-commits mailing list