Skip to content

Instantly share code, notes, and snippets.

@jonm
jonm / sockaddr-cast.txt
Last active October 10, 2015 19:50
missing a cast for the `bind` call
[~/src/SillyMUD/src]$ make
gcc -g -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -Werror -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -c -o comm.o comm.c
comm.c:755:14: error: incompatible pointer types passing 'struct sockaddr_in *'
to parameter of type 'const struct sockaddr *'
[-Werror,-Wincompatible-pointer-types]
if (bind(s, &sa, sizeof(sa)) < 0) {
^~~
/usr/include/sys/socket.h:557:38: note: passing argument to parameter here
int bind(int, const struct sockaddr *, socklen_t) __DARWIN_ALIAS(bind);
^
@jonm
jonm / name-conflict.txt
Created October 10, 2015 19:35
variable name conflicts with library function
[~/src/SillyMUD/src]$ make
gcc -g -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -Werror -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -c -o comm.o comm.c
comm.c:61:5: error: redefinition of 'reboot' as different kind of symbol
int reboot = 0; /* reboot the game after a shutdown */
^
/usr/include/unistd.h:680:6: note: previous definition is here
int reboot(int);
^
...
11 errors generated.
@jonm
jonm / explicit-braces.txt
Created October 10, 2015 19:28
it is good practice to be explicit about braces around conditional statements
[~/src/SillyMUD/src]$ make
gcc -g -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -Werror -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -c -o comm.o comm.c
comm.c:164:8: error: add explicit braces to avoid dangling else
[-Werror,-Wdangling-else]
} else if ((port = atoi(argv[pos])) <= 1024) {
^
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [comm.o] Error 1
@jonm
jonm / implicit-declaration.txt
Created October 10, 2015 19:15
implicit declaration errors
$ make
gcc -g -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -Werror -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -c -o comm.o comm.c
comm.c:163:25: error: implicit declaration of function 'atoi' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
} else if ((port = atoi(argv[pos])) <= 1024) {
^
...
20 errors generated.
make: *** [comm.o] Error 1
@jonm
jonm / compiler-warning-crypt.txt
Created October 10, 2015 18:59
sure enough, the compiler warned us about this
[~/src/SillyMUD/src]$ rm interpreter.o dmserver
[~/src/SillyMUD/src]$ make
gcc -g -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -c -o interpreter.o interpreter.c
...
interpreter.c:1255:19: warning: implicit declaration of function 'crypt' is
invalid in C99 [-Wimplicit-function-declaration]
if (strncmp(crypt(arg, d->character->player.name), d->pwd, 10)) {
^
...
interpreter.c:1335:21: warning: incompatible integer to pointer conversion
@jonm
jonm / library-segfault.c
Created October 10, 2015 18:51
where the segfault is happening in a library routine
strncpy(d->pwd, crypt(arg, d->character->player.name), 10);
/* This is an excerpt from a DikuMUD-derived codebase. DikuMUD was created by Sebastian Hammer, Michael Seifert</a>,
Hans Henrik Stærfeldt, Tom Madsen, and Katja Nyboe. This code is subject to the DikuMud License, as found at
https://github.com/jonm/SillyMUD/blob/43344e6dc864de7518c2fc0dbf7b7cf14f5924a2/doc/license.doc
*/
@jonm
jonm / gdb-run-password-segfault.txt
Created October 5, 2015 10:10
trying to find the password-related segfault
[~/src/SillyMUD]$ gdb src/dmserver
GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .. done
(gdb) run
@jonm
jonm / segfault-password.txt
Created October 5, 2015 01:34
we got a segfault when a new player tried to set a password
Sun Oct 4 21:30:35 2015 :: New connection from addr 127.0.0.1: 7: 7
Segmentation fault: 11
@jonm
jonm / password-barf.txt
Created October 5, 2015 01:32
game shut down while trying to set a password
What is thy name? Hobbes
Did I get that right, Hobbes (Y/N)? y
New character.
Give me a password for Hobbes:
Connection closed by foreign host.
@jonm
jonm / client-conn.txt
Created October 5, 2015 01:29
First client connection!
[~/src/SillyMUD/src]$ telnet localhost 4000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
__
/ \
\__
\ illy MUD version 1.2a