mirror of
https://github.com/sheumann/hush.git
synced 2025-01-10 16:29:44 +00:00
Change the ARRAY_SIZE macro to work around an ORCA/C limitation.
This commit is contained in:
parent
2b0d727f39
commit
3577d48e74
@ -1651,7 +1651,10 @@ extern const char bb_default_login_shell[] ALIGN1;
|
||||
#endif
|
||||
|
||||
|
||||
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
||||
#define ARRAY_SIZE(x) ((size_t)(sizeof(x) / sizeof((x)[0])))
|
||||
/* ORCA/C will sometimes barf on the expression in ARRAY_SIZE, depending on the element type
|
||||
* (e.g. for arrays of structs). When it does, use ARRAY_SIZE2 instead. */
|
||||
#define ARRAY_SIZE2(x, elttype) ((size_t)(sizeof(x) / sizeof(elttype)))
|
||||
|
||||
|
||||
/* We redefine ctype macros. Unicode-correct handling of char types
|
||||
|
10
shell/hush.c
10
shell/hush.c
@ -3108,7 +3108,7 @@ static const struct reserved_combo* match_reserved_word(o_string *word)
|
||||
};
|
||||
const struct reserved_combo *r;
|
||||
|
||||
for (r = reserved_list; r < reserved_list + ARRAY_SIZE(reserved_list); r++) {
|
||||
for (r = reserved_list; r < reserved_list + ARRAY_SIZE2(reserved_list, struct reserved_combo); r++) {
|
||||
if (strcmp(word->data, r->literal) == 0)
|
||||
return r;
|
||||
}
|
||||
@ -3999,7 +3999,7 @@ static int parse_dollar(o_string *as_string,
|
||||
if (last_ch == 0) /* error? */
|
||||
return 0;
|
||||
#else
|
||||
#error Simple code to only allow ${var} is not implemented
|
||||
#error "Simple code to only allow ${var} is not implemented"
|
||||
#endif
|
||||
if (as_string) {
|
||||
o_addstr(as_string, dest->data + pos);
|
||||
@ -6214,14 +6214,14 @@ static const struct built_in_command *find_builtin_helper(const char *name,
|
||||
}
|
||||
static const struct built_in_command *find_builtin1(const char *name)
|
||||
{
|
||||
return find_builtin_helper(name, bltins1, &bltins1[ARRAY_SIZE(bltins1)]);
|
||||
return find_builtin_helper(name, bltins1, &bltins1[ARRAY_SIZE2(bltins1, struct built_in_command)]);
|
||||
}
|
||||
static const struct built_in_command *find_builtin(const char *name)
|
||||
{
|
||||
const struct built_in_command *x = find_builtin1(name);
|
||||
if (x)
|
||||
return x;
|
||||
return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]);
|
||||
return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE2(bltins2, struct built_in_command)]);
|
||||
}
|
||||
|
||||
#if ENABLE_HUSH_FUNCTIONS
|
||||
@ -8723,7 +8723,7 @@ static int FAST_FUNC builtin_help(char **argv UNUSED_PARAM)
|
||||
printf(
|
||||
"Built-in commands:\n"
|
||||
"------------------\n");
|
||||
for (x = bltins1; x != &bltins1[ARRAY_SIZE(bltins1)]; x++) {
|
||||
for (x = bltins1; x != &bltins1[ARRAY_SIZE2(bltins1, struct built_in_command)]; x++) {
|
||||
if (x->b_descr)
|
||||
printf("%-10s%s\n", x->b_cmd, x->b_descr);
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ shell_builtin_ulimit(char **argv)
|
||||
}
|
||||
|
||||
if (opt_char == 'a') {
|
||||
for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE(limits_tbl)]; l++) {
|
||||
for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE2(limits_tbl, struct limits)]; l++) {
|
||||
getrlimit(l->cmd, &limit);
|
||||
printf("-%c: %-30s ", l->option, l->name);
|
||||
printlim(opts, &limit, l);
|
||||
@ -442,7 +442,7 @@ shell_builtin_ulimit(char **argv)
|
||||
|
||||
if (opt_char == 1)
|
||||
opt_char = 'f';
|
||||
for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE(limits_tbl)]; l++) {
|
||||
for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE2(limits_tbl, struct limits)]; l++) {
|
||||
if (opt_char == l->option) {
|
||||
char *val_str;
|
||||
|
||||
@ -489,7 +489,7 @@ shell_builtin_ulimit(char **argv)
|
||||
}
|
||||
} /* for (every possible opt) */
|
||||
|
||||
if (l == &limits_tbl[ARRAY_SIZE(limits_tbl)]) {
|
||||
if (l == &limits_tbl[ARRAY_SIZE2(limits_tbl, struct limits)]) {
|
||||
/* bad option. getopt already complained. */
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user