[Bug analyzer/114791] analyzer: file-leak not detected

2024-04-21 Thread urs at akk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791

--- Comment #5 from Urs Janßen  ---
-Wanalyzer-fd-leak has the same issue, no warning given for:

#define _DEFAULT_SOURCE 1
#include 
#include 
#include 
#include 
#include 

int main(void);

int main(void) {
int fd = -1;
int i = 0;
static const char *list[] = { "/tmp/", "/tmp/a", "/tmp/b", NULL };
struct stat st;

while (list[i] != NULL) {
if ((fd = open(list[i++], O_RDONLY)) != -1) {
if (fstat(fd, ) != -1) {
if ((st.st_mode & (S_IFREG | S_IFLNK)) && st.st_size > 0L)
break;
}
#ifdef NO_FILE_LEAK
close(fd);
fd = -1;
#endif /* NO_FILE_LEAK */
}
}

if (fd != -1)
close(fd);
}

[Bug analyzer/114791] analyzer: file-leak not detected

2024-04-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791

--- Comment #4 from Andrew Pinski  ---
Interesting, with -O0, there is a warning but that can be turned into a false
positive if you enable the "missing:" section.

[Bug analyzer/114791] analyzer: file-leak not detected

2024-04-20 Thread urs at akk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791

--- Comment #3 from Urs Janßen  ---
Comment on attachment 57998
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57998
minimal test case

>#include 
>#include 
>#include 
>#include 
>
>int main(void);
>
>int main(void) {
>FILE *fp = (FILE *) 0;
>int i = 0;
>static const char *list[] = { "/tmp/", "/tmp/a", "/tmp/b", NULL };
>struct stat st;
>
>while (list[i] != NULL) {
>if ((fp = fopen(list[i], "r")) != NULL) {

should be 
if ((fp = fopen(list[i++], "r")) != NULL) {

>if (fstat(fileno(fp), ) != -1) {
>if ((st.st_mode & (S_IFREG | S_IFLNK)) && st.st_size > 0L)
>break;
>}
>/* missing:
>fclose(fp);
>fp = NULL;
>here */
>}
>}
>
>if (fp)
>fclose(fp);
>}

[Bug analyzer/114791] analyzer: file-leak not detected

2024-04-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||diagnostic
   Last reconfirmed||2024-04-21
 Ever confirmed|0   |1
 Status|UNCONFIRMED |NEW

--- Comment #2 from Andrew Pinski  ---
Confirmed.

[Bug analyzer/114791] analyzer: file-leak not detected

2024-04-20 Thread urs at akk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791

--- Comment #1 from Urs Janßen  ---
Created attachment 57999
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57999=edit
preprocessed example