Skip to contentSkip to conversation

Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.

PATCH In review Allen 2 participants 3 messages Feb 8, 2019 s390

lore
Share & tools
lore

Allen

author
#0 lore raw

PATCH 1/1 Use ARRAY_SIZE instead of dividing sizeof array with sizeof an element.

From: Allen Pais <[email protected]>

This issue was detected with the help of Coccinelle.

---
 arch/s390/tools/gen_opcode_table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/tools/gen_opcode_table.c +1 -1
index a1bc02b29c81..468b70c85f62 100644
@@ -138,7 +138,7 @@ static struct insn_type *insn_format_to_type(char *format)
 	strcpy(tmp, format);
 	base_format = tmp;
 	base_format = strsep(&base_format, "_");
-	for (i = 0; i < sizeof(insn_type_table) / sizeof(insn_type_table[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {
 		ptr = insn_type_table[i].format;
 		while (*ptr) {
 			if (!strcmp(base_format, *ptr))
Signature · 1 line
2.19.1
#1 lore raw
Quoted 14 lines · Allen

From: Allen Pais <[email protected]>

This issue was detected with the help of Coccinelle.

---
 arch/s390/tools/gen_opcode_table.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/tools/gen_opcode_table.c +0 -0
index a1bc02b29c81..468b70c85f62 100644

arch/s390/tools/gen_opcode_table.c static struct insn_type *insn_format_to_type(char *format) · line 141

Quoted 5 lines
arch/s390/tools/gen_opcode_table.c +1 -1
@@ -138,7 +138,7 @@ static struct insn_type *insn_format_to_type(char *format)
 	strcpy(tmp, format);
 	base_format = tmp;
 	base_format = strsep(&base_format, "_");
-	for (i = 0; i < sizeof(insn_type_table) / sizeof(insn_type_table[0]); i++) {
+	for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {

This does not compile.

author
#2 lore raw
Quoted 14 lines

arch/s390/tools/gen_opcode_table.c static struct insn_type *insn_format_to_type(char *format) · line 141

Quoted 11 lines
arch/s390/tools/gen_opcode_table.c +1 -1
index a1bc02b29c81..468b70c85f62 100644
@@ -138,7 +138,7 @@ static struct insn_type *insn_format_to_type(char *format)
      strcpy(tmp, format);
      base_format = tmp;
      base_format = strsep(&base_format, "_");
-     for (i = 0; i < sizeof(insn_type_table) / sizeof(insn_type_table[0]); i++) {
+     for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {

This does not compile.

Surprising. I try it out again.

Thanks.

Signature · 1 line
       - Allen