jonm.dev

The Art of Writing Software



VerySillyMUD: Fixing the Rest of the Compiler Warnings

Series [ VerySillyMUD ]

This post is part of my “VerySillyMUD” series, chronicling an attempt to refactor an old MUD into working condition [ 1 ].

In our last episode, we used unit tests to document a function’s behavior so we could refactor it to fix a security warning. Now we are able to pick up where we left off three episodes ago: fixing compiler warnings to find any gotchas. To get started, let’s re-enable the -Werror compiler flag. Now, back to fixing warnings. I’ll just highlight the ones here that are novel cases we haven’t seen before. First up:

Ok, let’s get some context; here’s the function where that warning/error appears:

So we see that d is a struct descriptor_data *. A little grepping around shows that’s defined in structs.h:

Sure enough, we can see that d->host is a statically-allocated array. Now, this seems like a recipe for a buffer overrun to me, but one thing at a time. We’ll maybe find or fix that later by running lint or valgrind. For now, though, I’ll create an issue so we don’t forget, then we can just fix this to a simpler test and move on.

Well, it turns out that was the most interesting warning/error to highlight. In almost all cases it was pretty clear how to fix the warning, and often the compiler’s error message told me exactly how to fix it! Since there were a LOT of changes to get here, we’ll spare you the details. At this point, the game starts without most of the warnings we used to see. Hurrah! Now the only question is what to do for the next episode


[ 1 ] SillyMUD was a derivative of DikuMUD, which was originally created by Sebastian Hammer, Michael Seifert, Hans Henrik Stærfeldt, Tom Madsen, and Katja Nyboe.