From c0b0ba1f18aaeaaec2f43e874bc75e91b7e10784 Mon Sep 17 00:00:00 2001 From: dsl Date: Wed, 12 Apr 2006 19:49:59 +0000 Subject: [PATCH] If parameter don't have values, then 'continue' after setting the flag bit. Fixes coverty CID 776 and removes the need for a 'val = NULL' added to appease gcc's undefined variable tests. This parsing code sucks though, it doesn't correctly check for the '=' between a parameter and its value, whitespace can be used instead. --- usr.sbin/mtree/spec.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index ab7ea40e6f2c..bcb322e0f19f 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -1,4 +1,4 @@ -/* $NetBSD: spec.c,v 1.61 2005/10/01 20:28:22 christos Exp $ */ +/* $NetBSD: spec.c,v 1.62 2006/04/12 19:49:59 dsl Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -74,7 +74,7 @@ #if 0 static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: spec.c,v 1.61 2005/10/01 20:28:22 christos Exp $"); +__RCSID("$NetBSD: spec.c,v 1.62 2006/04/12 19:49:59 dsl Exp $"); #endif #endif /* not lint */ @@ -506,21 +506,20 @@ set(char *t, NODE *ip) char *kw, *val, *md, *ep; void *m; - val = NULL; while ((kw = strsep(&t, "= \t")) != NULL) { if (*kw == '\0') continue; if (strcmp(kw, "all") == 0) mtree_err("invalid keyword `all'"); ip->flags |= type = parsekey(kw, &value); - if (value) { - while ((val = strsep(&t, " \t")) != NULL && - *val == '\0') - continue; - if (val == NULL) - mtree_err("missing value"); - } - switch(type) { + if (!value) + /* Just set flag bit (F_IGN and F_OPT) */ + continue; + while ((val = strsep(&t, " \t")) != NULL && *val == '\0') + continue; + if (val == NULL) + mtree_err("missing value"); + switch (type) { case F_CKSUM: ip->cksum = strtoul(val, &ep, 10); if (*ep) @@ -548,9 +547,6 @@ set(char *t, NODE *ip) mtree_err("unknown group `%s'", val); ip->st_gid = gid; break; - case F_IGN: - /* just set flag bit */ - break; case F_MD5: if (val[0]=='0' && val[1]=='x') md=&val[2]; @@ -571,9 +567,6 @@ set(char *t, NODE *ip) if (*ep) mtree_err("invalid link count `%s'", val); break; - case F_OPT: - /* just set flag bit */ - break; case F_RMD160: if (val[0]=='0' && val[1]=='x') md=&val[2];