diff options
author | Mike Barcroft <mike@FreeBSD.org> | 2002-08-05 19:36:09 +0000 |
---|---|---|
committer | Mike Barcroft <mike@FreeBSD.org> | 2002-08-05 19:36:09 +0000 |
commit | 0f1bfcd28332b5e8b2192915509360f3c3763a6f (patch) | |
tree | 9e67dd4043d1461a3f6f81d7ee048728cb10cbed /lib | |
parent | 20fb589d139a45b5e64a1a94d680b9a499c894c5 (diff) | |
download | src-0f1bfcd28332b5e8b2192915509360f3c3763a6f.tar.gz src-0f1bfcd28332b5e8b2192915509360f3c3763a6f.zip |
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().
Notes
Notes:
svn path=/head/; revision=101403
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/fmtmsg.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/libc/gen/fmtmsg.c b/lib/libc/gen/fmtmsg.c index 121a8984efd8..e70a83b6ddef 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); } |