[llvm] r216415 - Fix bug in llvm::sys::argumentsFitWithinSystemLimits().

Rafael Espindola rafael.espindola at gmail.com
Mon Aug 25 15:53:22 PDT 2014


Author: rafael
Date: Mon Aug 25 17:53:21 2014
New Revision: 216415

URL: http://llvm.org/viewvc/llvm-project?rev=216415&view=rev
Log:
Fix bug in llvm::sys::argumentsFitWithinSystemLimits().

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.

Modified:
    llvm/trunk/lib/Support/Unix/Program.inc

Modified: llvm/trunk/lib/Support/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=216415&r1=216414&r2=216415&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Program.inc (original)
+++ llvm/trunk/lib/Support/Unix/Program.inc Mon Aug 25 17:53:21 2014
@@ -448,13 +448,13 @@ bool llvm::sys::argumentsFitWithinSystem
     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;
     }
   }





More information about the llvm-commits mailing list