Skip to content

Commit

Permalink
lib: If DEBUG is enabled, use a pointer type for data_stack_frame_t
Browse files Browse the repository at this point in the history
This allows telling static analyzers to treat t_push() and t_pop() similarly
to malloc()/free() and check for leaks.
  • Loading branch information
sirainen authored and GitLab committed Sep 2, 2016
1 parent 3c5ee51 commit 32c3ba3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/data-stack.c
Expand Up @@ -67,6 +67,12 @@ struct stack_frame_block {
#endif
};

#ifdef DEBUG
struct data_stack_frame {
int dummy;
};
#endif

data_stack_frame_t data_stack_frame = 0;

static bool data_stack_initialized = FALSE;
Expand Down Expand Up @@ -571,7 +577,7 @@ void data_stack_init(void)
return;
}
data_stack_initialized = TRUE;
data_stack_frame = 1;
data_stack_frame = (data_stack_frame_t)1;

outofmem_area.block.size = outofmem_area.block.left =
sizeof(outofmem_area) - sizeof(outofmem_area.block);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/data-stack.h
Expand Up @@ -31,7 +31,11 @@
overflows.
*/

#ifndef DEBUG
typedef unsigned int data_stack_frame_t;
#else
typedef struct data_stack_frame *data_stack_frame_t;
#endif

extern data_stack_frame_t data_stack_frame;

Expand Down

0 comments on commit 32c3ba3

Please sign in to comment.