Skip to content

Commit ce8f45b

Browse files
author
Craig Ringer
committed
Show that scan-build catches stack pointer escape indirection
1 parent 893926d commit ce8f45b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

c/clang_return_stack_checks/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
CC ?= clang
2-
CFLAGS ?= -Wall -Wextra
1+
ifeq ($(origin CC),default)
2+
CC = scan-build clang
3+
endif
4+
5+
ifeq ($(origin CFLAGS),default)
6+
CFLAGS = -Wall -Wextra
7+
endif
38

49
all: return_stack_escape
510

c/clang_return_stack_checks/guard.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
struct guard
55
{
66
int8_t guard_set;
7+
struct guard * previous;
78
};
89

910
extern struct guard * guard_ptr;
@@ -12,8 +13,8 @@ static void
1213
set_guard(struct guard * const g)
1314
{
1415
assert(!g->guard_set);
15-
assert(!guard_ptr);
1616
g->guard_set = 1;
17+
g->previous = guard_ptr;
1718
guard_ptr = g;
1819
}
1920

@@ -23,5 +24,6 @@ clear_guard(struct guard * const g)
2324
assert(g->guard_set);
2425
assert(guard_ptr);
2526
g->guard_set = 0;
26-
guard_ptr = 0;
27+
assert(guard_ptr == g);
28+
guard_ptr = guard_ptr->previous;
2729
}

0 commit comments

Comments
 (0)