From affb0159ffa5d61b141992a36f497e15240d3d83 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:22:06 -0700 Subject: [PATCH] Fix 1986/marshall for linux Choo choo! :-) There was a problem in linux where it either segfaulted or entered an infinite loop depending on compiler / flags. This was caused by a for loop that had an empty condition and the call to _exit(). A game of cat and mouse occurred where fixing it for one compiler caused the program to segfault with the other compiler. Unfortunately the formatting did have to change a bit but it still mostly looks like a train even if not quite as pretty. --- 1986/marshall/Makefile | 2 +- 1986/marshall/marshall.c | 24 ++++++++++++------------ thanks-for-fixes.md | 6 ++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/1986/marshall/Makefile b/1986/marshall/Makefile index d3f69bc73..5b8d62596 100644 --- a/1986/marshall/Makefile +++ b/1986/marshall/Makefile @@ -69,7 +69,7 @@ CINCLUDE= # Optimization # -OPT= -O3 +OPT= # Default flags for ANSI C compilation # diff --git a/1986/marshall/marshall.c b/1986/marshall/marshall.c index b7f685340..fafcfffc5 100644 --- a/1986/marshall/marshall.c +++ b/1986/marshall/marshall.c @@ -1,14 +1,14 @@ extern int - errno - ;char - grrr - ;main( r, - argv, argc ) char **argc , - r ; char *argv[];{int P( ); -#define x int i, j,cc[4];printf(" choo choo\n" ) ; -x ;if (P( ! i ) | cc[ ! j ] + errno + ;char + grrr + ;main( r, + argv, argc ) char **argc , + r ; char *argv[];{ int P( ); +#define x int i, j,cc[4]; printf(" choo choo\n" ) ; +x ;if (P( ! i ) | cc[ ! j ] & P(j )>2 ? j : i ){* argv[i++ +!-i] -; for (i= 0;; i++ ); -_exit(argv[(int)*argc-2/cc[1*(int)*argc]|-1<<4]);printf("%d",P(""));}} - P ( a ) char a ; { a ; while( a > " B " - /* - by E ricM arsh all- */); } +; /*for (i= 0;; i++ ); */ +_exit(1/*argv[(int)*argc-2/cc[1*(int)*argc]|-1<<4]*/);printf("%d",P("")) +;}} P ( a ) char a ; { a ; /*while( a > " B " + * - by E ricM arsh all- )*/; } diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index adbb11bab..add950176 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -144,6 +144,12 @@ was an `int`. He notes that he tried to keep the ASCII art as close to the original as possible. The line lengths are the same but some spaces had to be changed to non-spaces. +As the fix was it worked for macOS but it did not work for modern linux, not +before with gcc or after the fix with either gcc or clang, so Cody fixed that +too. This took some changes and commenting code out (commented out for the ASCII +art as noted). It was a game of cat and mouse where one fix with one compiler +caused it to segfault with the other but after commenting out two portions it +works fine. ## [1986/wall](1986/wall/wall.c) ([README.md](1986/wall/README.md]))