| 1 |
/* { dg-skip-if "" { powerpc*-*-aix* } } */ |
| 2 |
/* { dg-additional-options "-O2" } */ |
| 3 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
typedef struct AMARK { |
| 9 |
struct AMARK *m_next; |
| 10 |
char m_name; |
| 11 |
} AMARK; |
| 12 |
|
| 13 |
struct buf { |
| 14 |
AMARK *b_amark; |
| 15 |
}; |
| 16 |
|
| 17 |
struct buf *curbp; |
| 18 |
|
| 19 |
int pamark(void) { |
| 20 |
int c; |
| 21 |
AMARK *p = curbp->b_amark; |
| 22 |
AMARK *last = curbp->b_amark; |
| 23 |
|
| 24 |
c = getchar(); |
| 25 |
|
| 26 |
while (p != (AMARK *)NULL && p->m_name != (char)c) { |
| 27 |
last = p; |
| 28 |
p = p->m_next; |
| 29 |
} |
| 30 |
|
| 31 |
if (p != (AMARK *)NULL) { |
| 32 |
printf("over writing mark %c\n", c); |
| 33 |
} else { |
| 34 |
if ((p = (AMARK *)malloc(sizeof(AMARK))) == (AMARK *)NULL) |
| 35 |
return 0; |
| 36 |
|
| 37 |
p->m_next = (AMARK *)NULL; |
| 38 |
|
| 39 |
if (curbp->b_amark == (AMARK *)NULL) |
| 40 |
curbp->b_amark = p; |
| 41 |
else |
| 42 |
last->m_next = p; |
| 43 |
} |
| 44 |
|
| 45 |
p->m_name = (char)c; /* { dg-bogus "leak of 'p'" "bogus leak" } */ |
| 46 |
|
| 47 |
return 1; |
| 48 |
} |