summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2011-06-26 11:50:10 +0000
committerCarl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>2011-06-26 11:50:10 +0000
commit520e25c568ba37f0d428ae4c4ac55ac9223938a3 (patch)
tree07237d27fe48976a6a05894468d7daf7e5275761
parent603886c88eb6da8304b6786082fecb1b51557470 (diff)
downloadflashrom-520e25c568ba37f0d428ae4c4ac55ac9223938a3.zip
flashrom-520e25c568ba37f0d428ae4c4ac55ac9223938a3.tar.gz
Replace sizeof("string")-1 with strlen("string")
We want to avoid calls to strlen at runtime if the string is already known at compile time. Turns out that gcc and clang will recognize constant strings and compute the strlen result already at compile time, so trickery with sizeof only reduces readability but does not improve the code. Corresponding to flashrom svn r1352. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Sean Nelson <audiohacked@gmail.com> Acked-by: Uwe Hermann <uwe@hermann-uwe.de>
-rw-r--r--processor_enable.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/processor_enable.c b/processor_enable.c
index b14cd33..d680f97 100644
--- a/processor_enable.c
+++ b/processor_enable.c
@@ -56,13 +56,13 @@ static int is_loongson(void)
while (*ptr && isspace((unsigned char)*ptr))
ptr++;
/* "cpu" part appears only with some Linux versions. */
- if (strncmp(ptr, "cpu", sizeof("cpu") - 1) == 0)
- ptr += sizeof("cpu") - 1;
+ if (strncmp(ptr, "cpu", strlen("cpu")) == 0)
+ ptr += strlen("cpu");
while (*ptr && isspace((unsigned char)*ptr))
ptr++;
- if (strncmp(ptr, "model", sizeof("model") - 1) != 0)
+ if (strncmp(ptr, "model", strlen("model")) != 0)
continue;
- ptr += sizeof("model") - 1;
+ ptr += strlen("model");
while (*ptr && isspace((unsigned char)*ptr))
ptr++;
if (*ptr != ':')
@@ -72,9 +72,9 @@ static int is_loongson(void)
ptr++;
fclose(cpuinfo);
return (strncmp(ptr, "ICT Loongson-2 V0.3",
- sizeof("ICT Loongson-2 V0.3") - 1) == 0)
+ strlen("ICT Loongson-2 V0.3")) == 0)
|| (strncmp(ptr, "Godson2 V0.3 FPU V0.1",
- sizeof("Godson2 V0.3 FPU V0.1") - 1) == 0);
+ strlen("Godson2 V0.3 FPU V0.1")) == 0);
}
fclose(cpuinfo);
return 0;
OpenPOWER on IntegriCloud