[LLVMbugs] [Bug 9500] New: array[--buflen] fails when buflen is size_t (8 bytes)...

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 17 06:48:02 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=9500

           Summary: array[--buflen] fails when buflen is size_t (8
                    bytes)...
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: All
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: Fons.Rademakers at cern.ch
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Hi,

  the following code fails using the llvm trunk (and also in the Xcode4 2.9
version):

   G__FastAllocString ebuf(length);
   size_t lenbuf = 0;

   //
   // Operator expression.
   //
   for (ig1 = 0; ig1 < (int)length; ++ig1) {
      c = expression[ig1];
      if (!single_quote && !double_quote) {
         if (lenbuf > 1 && ebuf[lenbuf - 1] == ' ') {
            // we had a space - do we keep it?
            char beforeSpaceChar = ebuf[lenbuf - 2];
            if (((isalnum(c) || c == '_') && (isalnum(beforeSpaceChar) ||
beforeSpaceChar == '_'))
                || (c == '>' && beforeSpaceChar == '>')) {}
            else {
               // not two identifiers / template "> >" - replace the space
               ebuf[--lenbuf] = 0;      <---- mis compilation here
            }

Changing code as follows fixes it:

           else {
               // not two identifiers / template "> >" - replace the space
               lenbuf--;
               ebuf[lenbuf] = 0;
            }

 Or changing to int:

           else {
               // not two identifiers / template "> >" - replace the space
               int lb = int) lenbuf;
               ebuf[--lb] = 0;
            }

Running the original code under valgrind produces a valgrind error saying that
uninitialized variable of size 8 is used. So clang/llvm does not seem to pass
the update --lenbuf to the array operator.


Cheers, Fons.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list