From cedda2084d2f6b331ba0a73e05f0b77ee7995c86 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Mon, 24 Dec 2012 17:11:18 +0000 Subject: Sneaky valgrind trick to detect stack memory issues. After something is popped from a stack, we overwrite the memory with uninitialised data (if JQ_DEBUG is on). This means that valgrind reports use-after-pop as an uninitialised memory error. --- jv_alloc.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'jv_alloc.h') diff --git a/jv_alloc.h b/jv_alloc.h index 0613d587..b4e72c0d 100644 --- a/jv_alloc.h +++ b/jv_alloc.h @@ -3,6 +3,17 @@ #include +#if JQ_DEBUG +extern volatile char jv_mem_uninitialised; +#endif + +static void jv_mem_invalidate(void* mem, size_t n) { +#if JQ_DEBUG + char* m = mem; + while (n--) *m++ ^= jv_mem_uninitialised ^ jv_mem_uninitialised; +#endif +} + void* jv_mem_alloc(size_t); void jv_mem_free(void*); __attribute__((warn_unused_result)) void* jv_mem_realloc(void*, size_t); -- cgit v1.2.3