From 85842bfc7ce5acf3b4865b5c004da651d1305872 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Thu, 20 Apr 2023 13:41:57 -0700 Subject: [PATCH] Really fix segfault in 2001/bellard.otccex.c The segfault fix (that prevented it from working at all) that I made a while back was not actually complete. It should work fine now (famous last words but it does appear to work now with different values where it crashed). Some ints were used as pointers (including a function pointer). It should be noted again that 2000/bellard itself does not work but having this program bug fixed will be helpful for anyone who might want a crack at fixing bellard.c (see bugs.md). --- 2001/bellard/bellard.otccex.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2001/bellard/bellard.otccex.c b/2001/bellard/bellard.otccex.c index 9fdb8075a..71668a094 100644 --- a/2001/bellard/bellard.otccex.c +++ b/2001/bellard/bellard.otccex.c @@ -44,7 +44,7 @@ fact(n) /* Well, we could use printf, but it would be too easy */ print_num(n, b) { - int tab, p, c; + int *tab, *p, c; /* Numbers can be entered in decimal, hexadecimal ('0x' prefix) and octal ('0' prefix) */ /* more complex programs use malloc */ @@ -57,7 +57,7 @@ print_num(n, b) c = c + 'a' - 10; else c = c + '0'; - *(char *)p = c; + *p = c; p++; n = n / b; /* 'break' is supported */ @@ -66,7 +66,7 @@ print_num(n, b) } while (p != tab) { p--; - printf("%c", *(char *)p); + printf("%c", *p); } free(tab); } @@ -78,7 +78,7 @@ main(int argc, char **argv) supported. As long as you do not use a globally defined variable name as local variable (which is a bad habbit), you won't have any problem */ - int n, f, base; + int n, (*f)(), base; /* && and || operator have the same semantics as C (left to right evaluation and early exit) */