https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114791

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

>#include <sys/types.h>
>#include <sys/stat.h>
>#include <unistd.h>
>#include <stdio.h>
>
>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), &st) != -1) {
>                if ((st.st_mode & (S_IFREG | S_IFLNK)) && st.st_size > 0L)
>                    break;
>            }
>            /* missing:
>            fclose(fp);
>            fp = NULL;
>            here */
>        }
>    }
>
>    if (fp)
>        fclose(fp);
>}

Reply via email to