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.
This commit is contained in:
Daniel Glöckner 2008-09-11 19:17:40 +02:00 committed by grischka
parent 5a92536cea
commit 43a34d354a

3
tcc.c
View File

@ -9244,6 +9244,8 @@ static void gen_function(Sym *sym)
if (do_debug) { if (do_debug) {
put_stabn(N_FUN, 0, 0, ind - func_ind); 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 */ funcname = ""; /* for safety */
func_vt.t = VT_VOID; /* for safety */ func_vt.t = VT_VOID; /* for safety */
ind = 0; /* for safety */ ind = 0; /* for safety */
@ -9511,6 +9513,7 @@ static int tcc_compile(TCCState *s1)
#endif #endif
preprocess_init(s1); preprocess_init(s1);
cur_text_section = NULL;
funcname = ""; funcname = "";
anon_sym = SYM_FIRST_ANOM; anon_sym = SYM_FIRST_ANOM;