[LLVMbugs] [Bug 14675] New: clang doesn't warn (where gcc does) when reading too far in a C array

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Dec 20 13:59:03 PST 2012


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

             Bug #: 14675
           Summary: clang doesn't warn (where gcc does) when reading too
                    far in a C array
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sean at rogue-research.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


I was sad to discover that clang does not warn here:

---------
static void Set4 (const double arg[4])
{
  printf("%f %f %f %f \n", arg[0], arg[1], arg[2], arg[3]);
}

int main (void)
{
  double array[3] = {1.0, 2.0, 3.0};
  Set4(array);
  return 0;
}
---------

In C99, you could say "double arg[static 4]", but that does not help in C++.

Contrast with gcc:

$ gcc -Wuninitialized -O a.c
a.c: In function 'main':
a.c:5:13: warning: '*((void *)&array+24)' is used uninitialized in
this function [-Wuninitialized]
a.c:10:14: note: 'array' was declared here

$ gcc --version
gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)

-- 
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