Fix bug in llvm::sys::argumentsFitWithinSystemLimits().
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 25 Aug 2014 22:53:21 +0000 (22:53 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 25 Aug 2014 22:53:21 +0000 (22:53 +0000)
This patch fixes a subtle bug in the UNIX implementation of
llvm::sys::argumentsFitWithinSystemLimits() regarding the misuse of a static
variable. This bug causes our cached number that stores the system command line
maximum length to be halved after each call to the function. With a sufficient
number of calls to this function, it will eventually report any given command
line string to be over system limits.

Patch by Rafael Auler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216415 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Unix/Program.inc

index 06a33cd7790f22048cbdadebca38d1c6a39012d8..63d7ec22ebb0f4396fa3e28f95f9a3967077c262 100644 (file)
@@ -448,13 +448,13 @@ bool llvm::sys::argumentsFitWithinSystemLimits(ArrayRef<const char*> Args) {
     return true;
 
   // Conservatively account for space required by environment variables.
-  ArgMax /= 2;
+  long HalfArgMax = ArgMax / 2;
 
   size_t ArgLength = 0;
   for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
        I != E; ++I) {
     ArgLength += strlen(*I) + 1;
-    if (ArgLength > size_t(ArgMax)) {
+    if (ArgLength > size_t(HalfArgMax)) {
       return false;
     }
   }