Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/pr109577.c

raw
1 /* C only: C++ exceptions cause a malloc leak after "safer" returns.
2 Therefore this test has been duplicated as
3 c-c++-common/analyzer/pr109577-noexcept.c */
4
5 void *malloc (__SIZE_TYPE__);
6
7 double *
8 unsafe (__SIZE_TYPE__ n)
9 {
10 return (double *) malloc (n * sizeof (double));
11 }
12
13 double *
14 safer (__SIZE_TYPE__ n)
15 {
16 __SIZE_TYPE__ nbytes;
17 if (__builtin_mul_overflow (n, sizeof (double), &nbytes))
18 return 0;
19 return (double *) malloc (nbytes); /* Exceptions enabled cause a leak here. */
20 }