summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-03-11 07:04:54 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-03-11 07:04:54 +0000
commitf9ec2206c8fd7beb1cb407c308ea1400f7f39772 (patch)
tree3e5590dba52cecaa49153e7680c394decc7de2b3
parentff53e27258e3f6dead5265395789051d64abca96 (diff)
Fixes the `optindx' might be used uninitialized in this function
warning, fixes a spacing nit in a macro, and cleans up a very bad preprocessor abuse (``if LF_ISSET(OS_DEF)''!) optindx turns out to be the index number of the gigantic option list at the beginning of the file. All we need to do is set it before every ``goto err''. The first four are global options, which you can just set optindx to the second argument of o_set(). The last one is in a loop that uses cnt as the index. Since that is cnt's only use, I just removed cnt and used optindx instead. optindx is always updated and we use one less variable. ok miod, otto
-rw-r--r--usr.bin/vi/common/options.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/usr.bin/vi/common/options.c b/usr.bin/vi/common/options.c
index ba78641f3c7..dd820aa1b0c 100644
--- a/usr.bin/vi/common/options.c
+++ b/usr.bin/vi/common/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.12 2006/01/08 21:05:39 miod Exp $ */
+/* $OpenBSD: options.c,v 1.13 2006/03/11 07:04:53 ray Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -291,7 +291,7 @@ opts_init(sp, oargs)
ARGS *argv[2], a, b;
OPTLIST const *op;
u_long v;
- int cnt, optindx;
+ int optindx;
char *s, b1[1024];
a.bp = b1;
@@ -306,7 +306,7 @@ opts_init(sp, oargs)
(void)strlcpy(b1, (str), sizeof(b1)); \
a.len = strlen(b1); \
if (opts_set(sp, argv, NULL)) { \
- optindx = indx; \
+ optindx = indx; \
goto err; \
} \
}
@@ -315,17 +315,25 @@ opts_init(sp, oargs)
* terminal, lines, columns first, they're used by other options.
* Note, don't set the flags until we've set up the indirection.
*/
- if (o_set(sp, O_TERM, 0, NULL, GO_TERM))
+ if (o_set(sp, O_TERM, 0, NULL, GO_TERM)) {
+ optindx = O_TERM;
goto err;
+ }
F_SET(&sp->opts[O_TERM], OPT_GLOBAL);
- if (o_set(sp, O_LINES, 0, NULL, GO_LINES))
+ if (o_set(sp, O_LINES, 0, NULL, GO_LINES)) {
+ optindx = O_LINES;
goto err;
+ }
F_SET(&sp->opts[O_LINES], OPT_GLOBAL);
- if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS))
+ if (o_set(sp, O_COLUMNS, 0, NULL, GO_COLUMNS)) {
+ optindx = O_COLUMNS;
goto err;
+ }
F_SET(&sp->opts[O_COLUMNS], OPT_GLOBAL);
- if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE))
+ if (o_set(sp, O_SECURE, 0, NULL, GO_SECURE)) {
+ optindx = O_SECURE;
goto err;
+ }
F_SET(&sp->opts[O_SECURE], OPT_GLOBAL);
/* Initialize string values. */
@@ -399,20 +407,20 @@ opts_init(sp, oargs)
* Set boolean default values, and copy all settings into the default
* information. OS_NOFREE is set, we're copying, not replacing.
*/
- for (op = optlist, cnt = 0; op->name != NULL; ++op, ++cnt)
+ for (op = optlist, optindx = 0; op->name != NULL; ++op, ++optindx)
switch (op->type) {
case OPT_0BOOL:
break;
case OPT_1BOOL:
- O_SET(sp, cnt);
- O_D_SET(sp, cnt);
+ O_SET(sp, optindx);
+ O_D_SET(sp, optindx);
break;
case OPT_NUM:
- o_set(sp, cnt, OS_DEF, NULL, O_VAL(sp, cnt));
+ o_set(sp, optindx, OS_DEF, NULL, O_VAL(sp, optindx));
break;
case OPT_STR:
- if (O_STR(sp, cnt) != NULL && o_set(sp, cnt,
- OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, cnt), 0))
+ if (O_STR(sp, optindx) != NULL && o_set(sp, optindx,
+ OS_DEF | OS_NOFREE | OS_STRDUP, O_STR(sp, optindx), 0))
goto err;
break;
default:
@@ -766,7 +774,7 @@ o_set(sp, opt, flags, str, val)
}
/* Free the previous string, if requested, and set the value. */
- if LF_ISSET(OS_DEF)
+ if (LF_ISSET(OS_DEF))
if (LF_ISSET(OS_STR | OS_STRDUP)) {
if (!LF_ISSET(OS_NOFREE) && op->o_def.str != NULL)
free(op->o_def.str);