Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/pr93355-localealias-feasibility-3.c

raw
1 /* Simplified version of test to ensure we issue a FILE * leak diagnostic,
2 reproducing a feasibility issue.
3 Adapted from intl/localealias.c, with all #includes removed. */
4
5 /* { dg-do "compile" } */
6
7 /* Handle aliases for locale names.
8 Copyright (C) 1995-1999, 2000-2001, 2003 Free Software Foundation, Inc.
9
10 This program is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Library General Public License as published
12 by the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public
21 License along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
23 USA. */
24
25 /* Minimal version of system headers. */
26
27 typedef __SIZE_TYPE__ size_t;
28 #define NULL ((void *)0)
29
30 typedef struct _IO_FILE FILE;
31 extern FILE *fopen (const char *__restrict __filename,
32 const char *__restrict __modes);
33 extern int fclose (FILE *__stream);
34
35 extern int isspace (int) __attribute__((__nothrow__, __leaf__));
36
37 /* Cleaned-up body of localealias.c follows. */
38
39 size_t
40 read_alias_file (const char *fname, char *cp)
41 {
42 FILE *fp;
43
44 fp = fopen (fname, "r"); /* { dg-message "opened here" } */
45 if (fp == NULL)
46 return 0;
47
48 if (cp[0] != '\0')
49 *cp++ = '\0';
50
51 while (isspace ((unsigned char)cp[0]))
52 ++cp;
53
54 if (cp[0] != '\0')
55 return 42; /* { dg-warning "leak of FILE 'fp'" } */
56
57 fclose(fp);
58
59 return 0;
60 }