Fix 1985/applin under macOS

The solution is a curious one that I should have known. It wasn't even a
change in the code itself; rather in macOS one needs to include unistd.h
as with macOS without a proper prototype at least some functions do not
work right. This showed itself in 1984/anonymous as well though I had to
do a bit more to fix that one - provide a prototype in the code
(including the header file did not work - this was documented at one
point in the README.md and possibly bugs.md) and change the code
slightly as well. Ironically this was figured out through linux! See
bugs.md as I updated the on warnings section - this was an example entry
where some warnings are worth fixing.
This commit is contained in:
Cody Boone Ferguson committed 2023-04-27 05:54:50 -07:00
1 parent 3f2b5097e9
commit 0c12a6e6a1
3 files changed
+28 -18

No files matched your search

+1 -1
View File
@@ -61,7 +61,7 @@ CDEFINE=
# Include files that are needed to compile
#
CINCLUDE=
CINCLUDE= -include unistd.h
# Optimization
#
+8 -3
View File
@@ -16,9 +16,14 @@ make all
```
NOTE: [Yusuke Endoh](/winners.html#Yusuke_Endoh) provided a patch to get this to
not issue a bus error. Thank you Yusuke! [Cody Boone
Ferguson](/winners.html#Cody_Boone_Ferguson) noted that this entry does not work
under macOS. Try it out and see for yourself what happens!
not issue crash and [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson)
fixed this to work with macOS. The problem with the crash is that it
destructively rewrites string literals but with `strdup()` it's safe. For macOS
it's because there was no prototype for `execlp()` and macOS has problems with
missing prototypes for some functions (this was also seen when Cody fixed
[1984/anonymous](/1984/anonymous/anonymous.c) for macOS as well though that fix
was more complicated). Ironically this fix was discovered through linux! Thank
you Yusuke and Cody for your help!
## Judges' remarks:
+19 -14
View File
@@ -84,8 +84,9 @@ resolving these issues and has fixed many but you're welcome to have a go at it
too (though he'll be very sad if he doesn't have a chance to at first fix it :-(
so you might want to hold off for now :-) .. or not :-) ). He hopes to have most
of the remaining entries resolved in the near future but nevertheless if you're
okay making people very sad you may have a go at the entries :-) He'll remove
this part later on.
okay making people very sad you may have a go at the entries :-) [Yusuke
Endoh](/winners.html#Yusuke_Endoh) has also fixed a number of entries though at
this point he does not know it. :-) Cody will remove this part later on.
## General notes about the statuses and making fixes
@@ -112,9 +113,24 @@ segfault in macOS of [1989/paul](1994/paul/paul.c): changing the `int *` to a
But even if they are fixable (which will likely be hard to do) it's almost
certain that such code would be just as non-portable (importable ? :-) ).
In rare cases they are valid. For instance Cody noticed in linux the following
warning in [1985/applin](1985/applin/applin.c) with gcc:
```
applin.c:1:78: warning: incompatible implicit declaration of built-in function 'execlp' [-Wbuiltin-declaration-mismatch]
1 | main(v,c)char**c;{for(v[c++]=strdup("Hello, world!\n");(!!c)[*c]&&(v--||--c&&execlp(*c,*c,c[!!c]+!!c,!c));**c=!c)write(!!*c,*c,!!**c);}
| ^~~~~~
```
and this reminded him of his fix to
[1984/anonymous](1984/anonymous/anonymous.c). In the case of `1984/anonymous` it
was a bit more involved but with `1985/applin` one need only add to the Makefile
`-include unistd.h`. So there are some cases where fixing warnings can fix a
problem but in general they should be ignored even if they're annoying.
Hopefully with the example entries listed above you get the idea.
### General request on original code
### General request on original code:
If you're fixing an entry please make as few changes as possible! This is to
make it as close to the original but allowing it to work. This might be less of
@@ -363,17 +379,6 @@ arg.
# 1985
## [1985/applin](1985/applin/applin.c) ([README.md](1985/applin/README.md)
## STATUS: doesn't work with some platforms - please help us fix
[Yusuke Endoh](/winners.html#Yusuke_Endoh) provided a fix for gcc but
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) observed that this does
not work under macOS. It prints `H????????` with additional `?`s printed as it
continues to run.
We have not had a chance to try and fix this yet but you're welcome to have a go
at it.
# 1986