summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-06-03 22:04:36 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2010-06-03 23:17:21 +0400
commita73192497830167823d50ffb829f763ec270e7ef (patch)
tree397b0dd6ae437e40d055e130241d81e3676f2f2a
parent3b4e86b1ddc272cdf84f3e61486918100bb5e00f (diff)
downloadnasm-a73192497830167823d50ffb829f763ec270e7ef.tar.gz
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>
-rw-r--r--nasmlib.c2
-rw-r--r--nasmlib.h3
-rw-r--r--output/outform.c4
-rw-r--r--preproc.c6
4 files changed, 7 insertions, 8 deletions
diff --git a/nasmlib.c b/nasmlib.c
index 2ae86194..460186e6 100644
--- a/nasmlib.c
+++ b/nasmlib.c
@@ -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];
diff --git a/nasmlib.h b/nasmlib.h
index 02876c74..2c335e11 100644
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -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
diff --git a/output/outform.c b/output/outform.c
index f5b6739f..e386343e 100644
--- a/output/outform.c
+++ b/output/outform.c
@@ -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",
diff --git a/preproc.c b/preproc.c
index 2e870e58..7bfe2144 100644
--- a/preproc.c
+++ b/preproc.c
@@ -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]);