Skip to content

Instantly share code, notes, and snippets.

@jonm
jonm / first-test-run.txt
Created October 21, 2015 12:26
our first unit test passes!
[~/src/SillyMUD/src]$ make test
gcc -g -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -DIMPL_SECURITY -DNEW_RENT -DLEVEL_LOSS -DNEWEXP -DGROUP_NAMES -c -o test.act.wizard.o test.act.wizard.c
gcc -o tests comm.o act.comm.o act.info.o act.move.o act.obj1.o act.obj2.o act.off.o act.other.o act.social.o act.wizard.o handler.o db.o interpreter.o utility.o spec_assign.o shop.o limits.o mobact.o fight.o modify.o weather.o spells1.o spells2.o spell_parser.o reception.o constants.o spec_procs.o signals.o board.o magic.o magic2.o skills.o Opinion.o Trap.o magicutils.o multiclass.o hash.o Sound.o Heap.o spec_procs2.o magic3.o security.o spec_procs3.o create.o bsd.o parser.o intrinsics.o test.act.wizard.o -lcriterion
./tests
[====] Synthesis: Tested: 1 | Passing: 1 | Failing: 0 | Crashing: 0
@jonm
jonm / test.act.wizard.c
Last active October 19, 2015 18:40
first unit test
#include <stdio.h>
#include <criterion/criterion.h>
void dsearch(char *, char *);
Test(act_wizard, dsearch_simple) {
char arg[255], dst[255];
sprintf(arg, "Someone appears!");
dsearch(arg, dst);
cr_assert_str_eq(dst, "Someone appears!");
@jonm
jonm / dsearch.c
Created October 12, 2015 03:06
the `dsearch()` function
/* Bamfin and bamfout - courtesy of DM from Epic */
void dsearch(char *string, char *tmp)
{
char *c, buf[255], buf2[255], buf3[255];
int i, j;
i = 0;
while(i == 0) {
if(strchr(string, '~')==NULL) {
i = 1;
@jonm
jonm / insecure-fmt.txt
Created October 12, 2015 03:04
insecure(?) format string
[~/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 act.wizard.o act.wizard.c
act.wizard.c:243:24: error: format string is not a string literal
(potentially insecure) [-Werror,-Wformat-security]
sprintf(string, tmp);
^~~
/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
__builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
^
...
@jonm
jonm / function-pointer-type-error.txt
Created October 12, 2015 02:10
uh oh, function pointer type errors
[~/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 act.off.o act.off.c
act.off.c:1238:3: error: incompatible pointer types initializing 'void (*)()'
with an expression of type 'void (byte, struct char_data *, char *, int,
struct char_data *, struct obj_data *)'
[-Werror,-Wincompatible-pointer-types]
cast_geyser,
^~~~~~~~~~~
...
6 errors generated.
@jonm
jonm / extra-parens.txt
Created October 11, 2015 17:19
complaints about extraneous parentheses
[~/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 act.obj1.o act.obj1.c
act.obj1.c:51:39: error: equality comparison with extraneous parentheses
[-Werror,-Wparentheses-equality]
if((obj_object->obj_flags.type_flag == ITEM_MONEY)) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
act.obj1.c:51:39: note: remove extraneous parentheses around the comparison to
silence this warning
if((obj_object->obj_flags.type_flag == ITEM_MONEY)) {
~ ^ ~
@jonm
jonm / format-string-type-error.txt
Created October 10, 2015 20:21
catching type errors for arguments fed to format strings
[~/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 act.info.o act.info.c
act.info.c:2785:58: error: format specifies type 'int' but the argument has type
'long' [-Werror,-Wformat]
sprintf(buf, "Total number of rooms in world: %d\n\r", room_count);
~~ ^~~~~~~~~~
%ld
/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
__builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
^
@jonm
jonm / assignment-as-conditional.txt
Created October 10, 2015 20:10
using an assignment as a conditional
[~/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:1538:18: error: using the result of an assignment as a condition without
parentheses [-Werror,-Wparentheses]
while (*point = *(i++))
~~~~~~~^~~~~~~~
comm.c:1538:18: note: place parentheses around the assignment to silence this
warning
while (*point = *(i++))
^
@jonm
jonm / can_see_obj.c
Created October 10, 2015 20:06
definition of the CAN_SEE_OBJ function
int CAN_SEE_OBJ( struct char_data *ch, struct obj_data *obj)
{
if (IS_IMMORTAL(ch))
return(1);
/* ... */
return(1);
@jonm
jonm / can_see_obj.txt
Created October 10, 2015 20:04
where is CAN_SEE_OBJ declared?
[~/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:1514:18: error: implicit declaration of function 'CAN_SEE_OBJ' is invalid
in C99 [-Werror,-Wimplicit-function-declaration]
case 'o': i = OBJN(obj, to);
^
./utils.h:239:26: note: expanded from macro 'OBJN'
#define OBJN(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \
^
...