mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-02-17 17:19:35 +08:00
nasmlib: Rename elements() macro to ARRAY_SIZE
ARRAY_SIZE is a well known name pointing out that we're dealing with array in macro argument. Also to be on a safe side prefix_name helper should check the index been in bounds more precisely. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
parent
3b4e86b1dd
commit
a731924978
@ -570,7 +570,7 @@ static const char *prefix_names[] = {
|
||||
const char *prefix_name(int token)
|
||||
{
|
||||
unsigned int prefix = token-PREFIX_ENUM_START;
|
||||
if (prefix > elements(prefix_names))
|
||||
if (prefix >= ARRAY_SIZE(prefix_names))
|
||||
return NULL;
|
||||
|
||||
return prefix_names[prefix];
|
||||
|
@ -239,8 +239,7 @@ void standard_extension(char *inname, char *outname, char *extension);
|
||||
* This is a useful #define which I keep meaning to use more often:
|
||||
* the number of elements of a statically defined array.
|
||||
*/
|
||||
|
||||
#define elements(x) ( sizeof(x) / sizeof(*(x)) )
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/*
|
||||
* List handling
|
||||
|
@ -59,7 +59,7 @@ struct ofmt *ofmt_find(char *name)
|
||||
}
|
||||
|
||||
/* lets walk thru aliases then */
|
||||
for (i = 0; i < elements(ofmt_aliases); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
|
||||
if (ofmt_aliases[i].shortname &&
|
||||
!nasm_stricmp(name, ofmt_aliases[i].shortname))
|
||||
return ofmt_aliases[i].ofmt;
|
||||
@ -92,7 +92,7 @@ void ofmt_list(struct ofmt *deffmt, FILE * fp)
|
||||
}
|
||||
|
||||
/* lets walk through aliases then */
|
||||
for (i = 0; i < elements(ofmt_aliases); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
|
||||
if (!ofmt_aliases[i].shortname)
|
||||
continue;
|
||||
fprintf(fp, " %-10s%s\n",
|
||||
|
@ -482,7 +482,7 @@ static char *check_tasm_directive(char *line)
|
||||
|
||||
/* Binary search for the directive name */
|
||||
i = -1;
|
||||
j = elements(tasm_directives);
|
||||
j = ARRAY_SIZE(tasm_directives);
|
||||
q = nasm_skip_word(p);
|
||||
len = q - p;
|
||||
if (len) {
|
||||
@ -2005,7 +2005,7 @@ static int parse_size(const char *str) {
|
||||
static const int sizes[] =
|
||||
{ 0, 1, 4, 16, 8, 10, 2, 32 };
|
||||
|
||||
return sizes[bsii(str, size_names, elements(size_names))+1];
|
||||
return sizes[bsii(str, size_names, ARRAY_SIZE(size_names))+1];
|
||||
}
|
||||
|
||||
/*
|
||||
@ -3469,7 +3469,7 @@ static int find_cc(Token * t)
|
||||
return -1;
|
||||
|
||||
i = -1;
|
||||
j = elements(conditions);
|
||||
j = ARRAY_SIZE(conditions);
|
||||
while (j - i > 1) {
|
||||
k = (j + i) / 2;
|
||||
m = nasm_stricmp(t->text, conditions[k]);
|
||||
|
Loading…
Reference in New Issue
Block a user