| 1 |
/* As pr94851-1.c, but verify that we don't get confused by a call to |
| 2 |
an unknown function (PR analyzer/98575). */ |
| 3 |
|
| 4 |
/* { dg-additional-options "-O2" } */ |
| 5 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
typedef struct AMARK { |
| 11 |
struct AMARK *m_next; |
| 12 |
char m_name; |
| 13 |
} AMARK; |
| 14 |
|
| 15 |
struct buf { |
| 16 |
AMARK *b_amark; |
| 17 |
}; |
| 18 |
|
| 19 |
struct buf *curbp; |
| 20 |
|
| 21 |
extern void unknown_fn (void); |
| 22 |
|
| 23 |
int pamark(void) { |
| 24 |
int c; |
| 25 |
|
| 26 |
AMARK *p = curbp->b_amark; |
| 27 |
AMARK *last = curbp->b_amark; |
| 28 |
|
| 29 |
unknown_fn (); |
| 30 |
|
| 31 |
c = getchar (); |
| 32 |
|
| 33 |
while (p != (AMARK *)NULL && p->m_name != (char)c) { |
| 34 |
last = p; |
| 35 |
p = p->m_next; |
| 36 |
} |
| 37 |
|
| 38 |
if (p != (AMARK *)NULL) { |
| 39 |
printf("over writing mark %c\n", c); |
| 40 |
} else { |
| 41 |
if ((p = (AMARK *)malloc(sizeof(AMARK))) == (AMARK *)NULL) |
| 42 |
return 0; |
| 43 |
|
| 44 |
p->m_next = (AMARK *)NULL; |
| 45 |
|
| 46 |
if (curbp->b_amark == (AMARK *)NULL) |
| 47 |
curbp->b_amark = p; |
| 48 |
else |
| 49 |
last->m_next = p; /* { dg-warning "dereference of NULL 'last'" "deref" } */ |
| 50 |
} |
| 51 |
|
| 52 |
p->m_name = (char)c; /* { dg-bogus "leak of 'p'" "bogus leak" } */ |
| 53 |
|
| 54 |
return 1; |
| 55 |
} |