Skip to content

Commit 850f593

Browse files
committed
Define an ARRAY_SIZE macro which computes the size of a static array, and
use it where relevant.
1 parent 3e7a3c2 commit 850f593

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dmidecode.o : dmidecode.c version.h types.h util.h config.h dmidecode.h \
6060
dmiopt.h dmioem.h
6161
$(CC) $(CFLAGS) -c $< -o $@
6262

63-
dmiopt.o : dmiopt.c config.h types.h dmidecode.h dmiopt.h
63+
dmiopt.o : dmiopt.c config.h types.h util.h dmidecode.h dmiopt.h
6464
$(CC) $(CFLAGS) -c $< -o $@
6565

6666
dmioem.o : dmioem.c types.h dmidecode.h dmioem.h
@@ -75,7 +75,7 @@ ownership.o : ownership.c version.h types.h util.h config.h
7575
vpddecode.o : vpddecode.c version.h types.h util.h config.h vpdopt.h
7676
$(CC) $(CFLAGS) -c $< -o $@
7777

78-
vpdopt.o : vpdopt.c config.h vpdopt.h
78+
vpdopt.o : vpdopt.c config.h util.h vpdopt.h
7979
$(CC) $(CFLAGS) -c $< -o $@
8080

8181
util.o : util.c types.h util.h config.h

dmiopt.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "config.h"
2828
#include "types.h"
29+
#include "util.h"
2930
#include "dmidecode.h"
3031
#include "dmiopt.h"
3132

@@ -71,7 +72,7 @@ static void print_opt_type_list(void)
7172
unsigned int i;
7273

7374
fprintf(stderr, "Valid type keywords are:\n");
74-
for(i=0; i<sizeof(opt_type_keyword)/sizeof(struct type_keyword); i++)
75+
for(i=0; i<ARRAY_SIZE(opt_type_keyword); i++)
7576
{
7677
fprintf(stderr, " %s\n", opt_type_keyword[i].keyword);
7778
}
@@ -93,7 +94,7 @@ static u8 *parse_opt_type(u8 *p, const char *arg)
9394
}
9495

9596
/* First try as a keyword */
96-
for(i=0; i<sizeof(opt_type_keyword)/sizeof(struct type_keyword); i++)
97+
for(i=0; i<ARRAY_SIZE(opt_type_keyword); i++)
9798
{
9899
if(!strcasecmp(arg, opt_type_keyword[i].keyword))
99100
{
@@ -175,7 +176,7 @@ static void print_opt_string_list(void)
175176
unsigned int i;
176177

177178
fprintf(stderr, "Valid string keywords are:\n");
178-
for(i=0; i<sizeof(opt_string_keyword)/sizeof(struct string_keyword); i++)
179+
for(i=0; i<ARRAY_SIZE(opt_string_keyword); i++)
179180
{
180181
fprintf(stderr, " %s\n", opt_string_keyword[i].keyword);
181182
}
@@ -191,7 +192,7 @@ static int parse_opt_string(const char *arg)
191192
return -1;
192193
}
193194

194-
for(i=0; i<sizeof(opt_string_keyword)/sizeof(struct string_keyword); i++)
195+
for(i=0; i<ARRAY_SIZE(opt_string_keyword); i++)
195196
{
196197
if(!strcasecmp(arg, opt_string_keyword[i].keyword))
197198
{

util.h

+2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
#include "types.h"
44

5+
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
6+
57
int checksum(const u8 *buf, size_t len);
68
void *mem_chunk(size_t base, size_t len, const char *devmem);

vpdopt.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <getopt.h>
2626

2727
#include "config.h"
28+
#include "util.h"
2829
#include "vpdopt.h"
2930

3031

@@ -52,7 +53,7 @@ static void print_opt_string_list(void)
5253
unsigned int i;
5354

5455
fprintf(stderr, "Valid string keywords are:\n");
55-
for(i=0; i<sizeof(opt_string_keyword)/sizeof(struct string_keyword); i++)
56+
for(i=0; i<ARRAY_SIZE(opt_string_keyword); i++)
5657
{
5758
fprintf(stderr, " %s\n", opt_string_keyword[i].keyword);
5859
}
@@ -68,7 +69,7 @@ static int parse_opt_string(const char *arg)
6869
return -1;
6970
}
7071

71-
for(i=0; i<sizeof(opt_string_keyword)/sizeof(struct string_keyword); i++)
72+
for(i=0; i<ARRAY_SIZE(opt_string_keyword); i++)
7273
{
7374
if(!strcasecmp(arg, opt_string_keyword[i].keyword))
7475
{

0 commit comments

Comments
 (0)