From 366fe274ebb7b318fe042b3ab2e60bd81179f43e Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sat, 26 May 2012 13:58:42 +0200 Subject: unify use of sizeof() when computing array length Submitted by: 123 --- src/colors.c | 2 +- src/cssparser.cc | 2 +- src/keys.cc | 6 +++--- src/list.h | 4 ++-- src/prefsparser.cc | 2 +- src/uicmd.cc | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/colors.c b/src/colors.c index 5d929a88..dcb147e3 100644 --- a/src/colors.c +++ b/src/colors.c @@ -201,7 +201,7 @@ static const struct key { #endif }; -#define NCOLORS (sizeof(color_keyword) / sizeof(struct key)) +#define NCOLORS (sizeof(color_keyword) / sizeof(color_keyword[0])) /* * Parse a color in hex (RRGGBB) or (RGB) diff --git a/src/cssparser.cc b/src/cssparser.cc index ca41781e..8131372a 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -412,7 +412,7 @@ static const CssShorthandInfo Css_shorthand_info[] = { }; #define CSS_SHORTHAND_NUM \ - (sizeof(Css_shorthand_info) / sizeof(CssShorthandInfo)) + (sizeof(Css_shorthand_info) / sizeof(Css_shorthand_info[0])) /* ---------------------------------------------------------------------- * Parsing diff --git a/src/keys.cc b/src/keys.cc index 687d09fc..08d50306 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -149,7 +149,7 @@ void Keys::init() // Fill our key bindings list bindings = dList_new(32); - for (uint_t i = 0; i < sizeof(default_keys) / sizeof(KeyBinding_t); i++) { + for (uint_t i = 0; i < sizeof(default_keys) / sizeof(default_keys[0]); i++) { if (default_keys[i].key) { node = dNew(KeyBinding_t, 1); node->name = dStrdup(default_keys[i].name); @@ -244,7 +244,7 @@ void Keys::delKeyCmd(int key, int mod) int Keys::getKeyCode(char *keyName) { uint_t i; - for (i = 0; i < sizeof(keyNames) / sizeof(Mapping_t); i++) { + for (i = 0; i < sizeof(keyNames) / sizeof(keyNames[0]); i++) { if (!dStrAsciiCasecmp(keyNames[i].name, keyName)) { return keyNames[i].value; } @@ -275,7 +275,7 @@ KeysCommand_t Keys::getCmdCode(const char *commandName) int Keys::getModifier(char *modifierName) { uint_t i; - for (i = 0; i < sizeof(modifierNames) / sizeof(Mapping_t); i++) { + for (i = 0; i < sizeof(modifierNames) / sizeof(modifierNames[0]); i++) { if (!dStrAsciiCasecmp(modifierNames[i].name, modifierName)) { return modifierNames[i].value; } diff --git a/src/list.h b/src/list.h index 8623bf09..f98661d1 100644 --- a/src/list.h +++ b/src/list.h @@ -16,12 +16,12 @@ */ #define a_List_resize(list,num_items,alloc_step) \ if (!list) { \ - list = dMalloc(alloc_step * sizeof((*list))); \ + list = dMalloc(alloc_step * sizeof(*list)); \ } \ if (num_items >= alloc_step){ \ while ( num_items >= alloc_step ) \ alloc_step <<= 1; \ - list = dRealloc(list, alloc_step * sizeof((*list))); \ + list = dRealloc(list, alloc_step * sizeof(*list)); \ } diff --git a/src/prefsparser.cc b/src/prefsparser.cc index 7fd6cf4a..e74b5a6f 100644 --- a/src/prefsparser.cc +++ b/src/prefsparser.cc @@ -113,7 +113,7 @@ int PrefsParser::parseOption(char *name, char *value) }; node = NULL; - for (i = 0; i < sizeof(symbols) / sizeof(SymNode_t); i++) { + for (i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) { if (!strcmp(symbols[i].name, name)) { node = & (symbols[i]); break; diff --git a/src/uicmd.cc b/src/uicmd.cc index b02a5746..6ca98280 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -1177,7 +1177,7 @@ void a_UIcmd_scroll(BrowserWindow *bw, int icmd) }; KeysCommand_t keycmd = (KeysCommand_t)icmd; - for (uint_t i = 0; i < (sizeof(map)/sizeof(mapping_t)); i++) { + for (uint_t i = 0; i < sizeof(map) / sizeof(map[0]); i++) { if (keycmd == map[i].keys_cmd) { layout->scroll(map[i].dw_cmd); break; -- cgit v1.2.3