aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/strcmp-1.c
blob: cc50a6fdba595b378f29cede79770aedfb969aff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* Verify that we clarify the sense of paths involving strcmp.  */

#include <string.h>
#include <stdlib.h>

int test_1 (const char *str, char *ptr)
{
  if (strcmp (str, "VALUE")) /* { dg-message "following 'true' branch \\(when the strings are non-equal\\)\\.\\.\\." } */
    free (ptr);
  free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
}

int test_2 (const char *str, char *ptr)
{
  if (strcmp (str, "VALUE") == 0) /* { dg-message "following 'true' branch \\(when the strings are equal\\)\\.\\.\\." } */
    free (ptr);
  free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
}

int test_3 (const char *str, char *ptr)
{
  if (!strcmp (str, "VALUE")) /* { dg-message "following 'true' branch \\(when the strings are equal\\)\\.\\.\\." } */
    free (ptr);
  free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
}

int test_4 (const char *str, char *ptr)
{
  if (strcmp (str, "VALUE")) /* { dg-message "following 'false' branch \\(when the strings are equal\\)\\.\\.\\." } */
    {
    }
  else
    free (ptr);
  free (ptr); /* { dg-warning "double-'free' of 'ptr'" } */
}