Skip to content

Commit b4f2a6a

Browse files
author
Junio C Hamano
committed
Use #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bd7f28 commit b4f2a6a

File tree

5 files changed

+5
-7
lines changed

5 files changed

+5
-7
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static int parse_git_header(char *line, int len, unsigned int size, struct patch
651651
len = linelen(line, size);
652652
if (!len || line[len-1] != '\n')
653653
break;
654-
for (i = 0; i < sizeof(optable) / sizeof(optable[0]); i++) {
654+
for (i = 0; i < ARRAY_SIZE(optable); i++) {
655655
const struct opentry *p = optable + i;
656656
int oplen = strlen(p->str);
657657
if (len < oplen || memcmp(p->str, line, oplen))

date.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ static const struct {
123123
{ "IDLE", +12, 0, }, /* International Date Line East */
124124
};
125125

126-
#define NR_TZ (sizeof(timezone_names) / sizeof(timezone_names[0]))
127-
128126
static int match_string(const char *date, const char *str)
129127
{
130128
int i = 0;
@@ -173,7 +171,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
173171
}
174172
}
175173

176-
for (i = 0; i < NR_TZ; i++) {
174+
for (i = 0; i < ARRAY_SIZE(timezone_names); i++) {
177175
int match = match_string(date, timezone_names[i].name);
178176
if (match >= 3) {
179177
int off = timezone_names[i].offset;

exec_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int execv_git_cmd(const char **argv)
3737
getenv("GIT_EXEC_PATH"),
3838
builtin_exec_path };
3939

40-
for (i = 0; i < sizeof(paths)/sizeof(paths[0]); ++i) {
40+
for (i = 0; i < ARRAY_SIZE(paths); ++i) {
4141
const char *exec_dir = paths[i];
4242
const char *tmp;
4343

git-compat-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#endif
1010
#endif
1111

12+
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
13+
1214
#include <unistd.h>
1315
#include <stdio.h>
1416
#include <sys/stat.h>

git.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,6 @@ static int cmd_log(int argc, const char **argv, char **envp)
323323
return 0;
324324
}
325325

326-
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
327-
328326
static void handle_internal_command(int argc, const char **argv, char **envp)
329327
{
330328
const char *cmd = argv[0];

0 commit comments

Comments
 (0)