https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98905
Bug ID: 98905 Summary: lstat() confused with wrong struct stat Product: gcc Version: 5.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gcc at madler dot net Target Milestone: --- When compiling on Solaris (SunOS gcc-solaris11 5.11 11.3 sun4u sparc SUNW,SPARC-Enterprise) using gcc 5.5.0 with a particular set of macros defined, lstat() thinks its writing to a different struct stat than the struct stat that is declared. This result in bogus values for the struct elements. Here is a sample program: #define _FILE_OFFSET_BITS 64 #define _XOPEN_SOURCE 600 #include <stdio.h> #include <sys/stat.h> int main(int argc, char **argv) { for (int i = 1; i < argc; i++) { struct stat st; int ret = lstat(argv[i], &st); printf("%s: lstat() returned %d, mode = %lx, size = %llu\n", argv[i], ret, st.st_mode, st.st_size); } return 0; } This will generally print a value like 1 or 2 for mode (should be 0x8zzz for a file), and a giant number for size. Three things are required together to manifest the bug: the two #define's and the use of lstat(). If either of the defines is removed or stat() is used, the bug does not manifest. Example output: lstat-bug: lstat() returned 0, mode = 1, size = 6923981885842223364 lstat-bug.c: lstat() returned 0, mode = 1, size = 6923981159521138040