From 43a34d354a6a3b0df07ed065adb050c0dda9abaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gl=C3=B6ckner?= Date: Thu, 11 Sep 2008 19:17:40 +0200 Subject: [PATCH] Force null pointer exception for code outside of a function TinyCC sometimes has problems to evaluate constant expressions at compile time. This leads to code being generated outside of functions. Without this patch some of these bugs are not caught, because cur_text_section still points to the section of the last function. Before the first function cur_text_section is uninitialized. Setting cur_text_section to a null pointer should make TinyCC die in all cases. --- tcc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tcc.c b/tcc.c index 98d8de6..81237a9 100644 --- a/tcc.c +++ b/tcc.c @@ -9244,6 +9244,8 @@ static void gen_function(Sym *sym) if (do_debug) { put_stabn(N_FUN, 0, 0, ind - func_ind); } + /* It's better to crash than to generate wrong code */ + cur_text_section = NULL; funcname = ""; /* for safety */ func_vt.t = VT_VOID; /* for safety */ ind = 0; /* for safety */ @@ -9511,6 +9513,7 @@ static int tcc_compile(TCCState *s1) #endif preprocess_init(s1); + cur_text_section = NULL; funcname = ""; anon_sym = SYM_FIRST_ANOM;