summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2002-08-05 19:36:09 +0000
committermike <mike@FreeBSD.org>2002-08-05 19:36:09 +0000
commitd79b2f269bc252549be609a5cfa1862de0939d61 (patch)
tree9e67dd4043d1461a3f6f81d7ee048728cb10cbed /lib
parent98877a3b30d997a675dfdb82704cb5b5dc6b51a9 (diff)
downloadFreeBSD-src-d79b2f269bc252549be609a5cfa1862de0939d61.zip
FreeBSD-src-d79b2f269bc252549be609a5cfa1862de0939d61.tar.gz
o Fix a memory leak.
o Rewrite validmsgverb() so that it works (I'm not sure how it escaped my original testing). o Document nextcomp().
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/fmtmsg.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c
index 121a898..e70a83b 100644
--- a/lib/libc/gen/fmtmsg.c
+++ b/lib/libc/gen/fmtmsg.c
@@ -61,8 +61,10 @@ fmtmsg(long class, const char *label, int sev, const char *text,
strlen(env) <= strlen(DFLT_MSGVERB)) {
if ((msgverb = strdup(env)) == NULL)
return (MM_NOTOK);
- else if (validmsgverb(msgverb) == 0)
+ else if (validmsgverb(msgverb) == 0) {
+ free(msgverb);
goto def;
+ }
} else {
def:
if ((msgverb = strdup(DFLT_MSGVERB)) == NULL)
@@ -155,6 +157,11 @@ printfmt(char *msgverb, long class, const char *label, int sev,
return (output);
}
+/*
+ * Returns a component of a colon delimited string. NULL is returned to
+ * indicate that there are no remaining components. This function must be
+ * called until it returns NULL in order for the local state to be cleared.
+ */
static char *
nextcomp(const char *msgverb)
{
@@ -197,18 +204,15 @@ static int
validmsgverb(const char *msgverb)
{
char *msgcomp;
- const char *validcomp;
+ int i, equality;
+ equality = 0;
while ((msgcomp = nextcomp(msgverb)) != NULL) {
- if (*msgcomp == '\0')
- return (0);
- for (validcomp = *validlist;
- validcomp != NULL; validcomp++) {
- if (strcmp(msgcomp, validcomp) == 0)
- break;
+ equality--;
+ for (i = 0; validlist[i] != NULL; i++) {
+ if (strcmp(msgcomp, validlist[i]) == 0)
+ equality++;
}
- if (validcomp == NULL)
- return (0);
}
- return (1);
+ return (!equality);
}
OpenPOWER on IntegriCloud