mirror of
https://gcc.gnu.org/git/gcc.git
synced 2025-01-20 11:23:57 +08:00
analyzer: bulletproof -Wanalyzer-file-leak [PR101547]
gcc/analyzer/ChangeLog: PR analyzer/101547 * sm-file.cc (file_leak::emit): Handle m_arg being NULL. (file_leak::describe_final_event): Handle ev.m_expr being NULL. gcc/testsuite/ChangeLog: PR analyzer/101547 * gcc.dg/analyzer/pr101547.c: New test. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
parent
87bd75cd49
commit
893b12cc12
@ -193,9 +193,13 @@ public:
|
|||||||
/* CWE-775: "Missing Release of File Descriptor or Handle after
|
/* CWE-775: "Missing Release of File Descriptor or Handle after
|
||||||
Effective Lifetime". */
|
Effective Lifetime". */
|
||||||
m.add_cwe (775);
|
m.add_cwe (775);
|
||||||
return warning_meta (rich_loc, m, OPT_Wanalyzer_file_leak,
|
if (m_arg)
|
||||||
"leak of FILE %qE",
|
return warning_meta (rich_loc, m, OPT_Wanalyzer_file_leak,
|
||||||
m_arg);
|
"leak of FILE %qE",
|
||||||
|
m_arg);
|
||||||
|
else
|
||||||
|
return warning_meta (rich_loc, m, OPT_Wanalyzer_file_leak,
|
||||||
|
"leak of FILE");
|
||||||
}
|
}
|
||||||
|
|
||||||
label_text describe_state_change (const evdesc::state_change &change)
|
label_text describe_state_change (const evdesc::state_change &change)
|
||||||
@ -212,10 +216,21 @@ public:
|
|||||||
label_text describe_final_event (const evdesc::final_event &ev) FINAL OVERRIDE
|
label_text describe_final_event (const evdesc::final_event &ev) FINAL OVERRIDE
|
||||||
{
|
{
|
||||||
if (m_fopen_event.known_p ())
|
if (m_fopen_event.known_p ())
|
||||||
return ev.formatted_print ("%qE leaks here; was opened at %@",
|
{
|
||||||
ev.m_expr, &m_fopen_event);
|
if (ev.m_expr)
|
||||||
|
return ev.formatted_print ("%qE leaks here; was opened at %@",
|
||||||
|
ev.m_expr, &m_fopen_event);
|
||||||
|
else
|
||||||
|
return ev.formatted_print ("leaks here; was opened at %@",
|
||||||
|
&m_fopen_event);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return ev.formatted_print ("%qE leaks here", ev.m_expr);
|
{
|
||||||
|
if (ev.m_expr)
|
||||||
|
return ev.formatted_print ("%qE leaks here", ev.m_expr);
|
||||||
|
else
|
||||||
|
return ev.formatted_print ("leaks here");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
11
gcc/testsuite/gcc.dg/analyzer/pr101547.c
Normal file
11
gcc/testsuite/gcc.dg/analyzer/pr101547.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
char *
|
||||||
|
fopen (const char *restrict, const char *restrict);
|
||||||
|
|
||||||
|
void
|
||||||
|
k2 (void)
|
||||||
|
{
|
||||||
|
char *setfiles[1];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
setfiles[i] = fopen ("", ""); /* { dg-warning "use of uninitialized value 'i'" } */
|
||||||
|
} /* { dg-warning "leak of FILE" } */
|
Loading…
Reference in New Issue
Block a user