From cf74f1cfd8201a14fef3b76e346b411fd263a22c Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 13 Apr 2015 17:21:59 -0700 Subject: [PATCH] regex lint For the POSIX regexp interface, move local declaration to beginning of block to avoid requiring C99. Also switch to alloc() from bare malloc() so that MONITOR_HEAP won't log a free which doesn't match up to any allocation. This results in a change in behavior: if the allocation fails, nethack will panic rather than report an option parsing error. In practice there will be no difference because nethack is not going to run out of dynamic memory during initial options processing. --- sys/share/posixregex.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sys/share/posixregex.c b/sys/share/posixregex.c index 17cb2841e..3540d3b4c 100644 --- a/sys/share/posixregex.c +++ b/sys/share/posixregex.c @@ -1,8 +1,8 @@ -/* NetHack 3.5 posixregex.c $NHDT-Date: 1428590280 2015/04/09 14:38:00 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.0 $ */ +/* NetHack 3.5 posixregex.c $NHDT-Date: 1428970913 2015/04/14 00:21:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */ /* Copyright (c) Sean Hunt 2015. */ /* NetHack may be freely redistributed. See license for details. */ -#include +#include "hack.h" #include @@ -50,7 +50,7 @@ struct nhregex { }; struct nhregex *regex_init() { - return malloc (sizeof (struct nhregex)); + return (struct nhregex *)alloc(sizeof (struct nhregex)); } boolean regex_compile(const char *s, struct nhregex *re) { @@ -65,7 +65,7 @@ const char *regex_error_desc(struct nhregex *re) { static char buf[BUFSZ]; if (!re || !re->err) - return NULL; + return (const char *)0; /* FIXME: Using a static buffer here is not ideal, but avoids memory * leaks. Consider the allocation more carefully. */ @@ -75,11 +75,12 @@ const char *regex_error_desc(struct nhregex *re) { } boolean regex_match(const char *s, struct nhregex *re) { + int result; + if (!re) return FALSE; - int result; - if ((result = regexec(&re->re, s, 0, NULL, 0))) { + if ((result = regexec(&re->re, s, 0, (genericptr_t)0, 0))) { if (result != REG_NOMATCH) re->err = result; return FALSE;