Possible fix for Coverity CID#7:
convert options() prototype to unsigned (size_t, in fact), and make an explicitly casted (size_t)-1 the error return code, modelled after what is often used in Unix libraries
This commit is contained in:
20
misc.c
20
misc.c
@ -6,7 +6,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.53 2007/05/13 17:51:23 tg Exp $\t"
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.54 2007/05/13 18:33:29 tg Exp $\t"
|
||||
MKSH_SH_H_ID);
|
||||
|
||||
#undef USE_CHVT
|
||||
@ -145,16 +145,16 @@ const struct option options[] = {
|
||||
/*
|
||||
* translate -o option into F* constant (also used for test -o option)
|
||||
*/
|
||||
int
|
||||
size_t
|
||||
option(const char *n)
|
||||
{
|
||||
unsigned i;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < NELEM(options); i++)
|
||||
if (options[i].name && strcmp(options[i].name, n) == 0)
|
||||
return i;
|
||||
return (i);
|
||||
|
||||
return -1;
|
||||
return ((size_t)-1);
|
||||
}
|
||||
|
||||
struct options_info {
|
||||
@ -277,8 +277,8 @@ parse_args(const char **argv,
|
||||
char *opts;
|
||||
const char *array = NULL;
|
||||
Getopt go;
|
||||
size_t i;
|
||||
int optc, set, sortargs = 0, arrayset = 0;
|
||||
unsigned i;
|
||||
|
||||
/* First call? Build option strings... */
|
||||
if (cmd_opts[0] == '\0') {
|
||||
@ -350,18 +350,18 @@ parse_args(const char **argv,
|
||||
break;
|
||||
}
|
||||
i = option(go.optarg);
|
||||
if (i != (unsigned)-1 && set == Flag(i))
|
||||
if ((i != (size_t)-1) && set == Flag(i))
|
||||
/* Don't check the context if the flag
|
||||
* isn't changing - makes "set -o interactive"
|
||||
* work if you're already interactive. Needed
|
||||
* if the output of "set +o" is to be used.
|
||||
*/
|
||||
;
|
||||
else if (i != (unsigned)-1 && (options[i].flags & what))
|
||||
change_flag((enum sh_flag) i, what, set);
|
||||
else if ((i != (size_t)-1) && (options[i].flags & what))
|
||||
change_flag((enum sh_flag)i, what, set);
|
||||
else {
|
||||
bi_errorf("%s: bad option", go.optarg);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user