Skip to contentSkip to conversation

kdb: Replace strncmp with str_has_prefix

PATCH In review Chuhong Yuan 2 participants 2 messages Jul 29, 2019 – Jul 30, 2019 KGDB / KDB /debug_core

lore
Share & tools
lore
#0 lore raw

PATCH 2/12 kdb: Replace strncmp with str_has_prefix

strncmp(str, const, len) is error-prone.
We had better use newly introduced
str_has_prefix() instead of it.

---
 kernel/debug/kdb/kdb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_main.c +1 -1
index 9ecfa37c7fbf..4567fe998c30 100644
@@ -830,7 +830,7 @@ static void parse_grep(const char *str)
 	cp++;
 	while (isspace(*cp))
 		cp++;
-	if (strncmp(cp, "grep ", 5)) {
+	if (!str_has_prefix(cp, "grep ")) {
 		kdb_printf("invalid 'pipe', see grephelp\n");
 		return;
 	}
Signature · 1 line
2.20.1
Acked-by on v1 2/12
#1 lore raw
Quoted 5 lines · Chuhong Yuan

strncmp(str, const, len) is error-prone.
We had better use newly introduced
str_has_prefix() instead of it.

Quoted 20 lines
---
 kernel/debug/kdb/kdb_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_main.c +1 -1
index 9ecfa37c7fbf..4567fe998c30 100644
@@ -830,7 +830,7 @@ static void parse_grep(const char *str)
 	cp++;
 	while (isspace(*cp))
 		cp++;
-	if (strncmp(cp, "grep ", 5)) {
+	if (!str_has_prefix(cp, "grep ")) {
 		kdb_printf("invalid 'pipe', see grephelp\n");
 		return;
 	}
Signature · 1 line
2.20.1