[llvm-commits] [llvm] r59131 - /llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Wed Nov 12 04:41:18 PST 2008


Author: foldr
Date: Wed Nov 12 06:41:18 2008
New Revision: 59131

URL: http://llvm.org/viewvc/llvm-project?rev=59131&view=rev
Log:
Check the return value of std::getenv.

When constructing std::strings from C strings, we should check the input
value to be not NULL so that the std::string constructor does not
segfault.
Fixes #3047.

Modified:
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=59131&r1=59130&r2=59131&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Wed Nov 12 06:41:18 2008
@@ -1121,9 +1121,9 @@
     if (cmd.size() == 5)
       throw std::string("$ENV invocation: empty argument list!");
 
-    ret += "std::getenv(\"";
+    ret += "checkCString(std::getenv(\"";
     ret += std::string(cmd.begin() + 5, cmd.begin() + cparen);
-    ret += "\")";
+    ret += "\"))";
   }
   else {
     throw "Unknown special command: " + cmd;
@@ -1729,7 +1729,8 @@
     << "static llvmc::RegisterPlugin<Plugin> RP;\n\n}\n\n";
 }
 
-/// EmitInclude - Emit necessary #include directives.
+/// EmitIncludes - Emit necessary #include directives and some
+/// additional declarations.
 void EmitIncludes(std::ostream& O) {
   O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
     << "#include \"llvm/CompilerDriver/Plugin.h\"\n"
@@ -1744,7 +1745,10 @@
     << "using namespace llvm;\n"
     << "using namespace llvmc;\n\n"
 
-    << "extern cl::opt<std::string> OutputFilename;\n\n";
+    << "extern cl::opt<std::string> OutputFilename;\n\n"
+
+    << "inline const char* checkCString(const char* s)\n"
+    << "{ return s == NULL ? \"\" : s; }\n\n";
 }
 
 // End of anonymous namespace





More information about the llvm-commits mailing list