Skip to content

Commit 7c82d0d

Browse files
evelikovlucasdemarchi
authored andcommitted
libkmod: use strstartswith() over memcmp()
In the cases where we have a string literal, we can use our helper without adding performance overhead. Signed-off-by: Emil Velikov <[email protected]> Link: #354 Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 0b116d8 commit 7c82d0d

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

libkmod/libkmod-config.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,9 @@ static int kmod_config_add_softdep(struct kmod_config *config, const char *modna
267267
}
268268
plen = s - p;
269269

270-
if (plen == strlen("pre:") && memcmp(p, "pre:", strlen("pre:")) == 0)
270+
if (plen == strlen("pre:") && strstartswith(p, "pre:"))
271271
mode = S_PRE;
272-
else if (plen == strlen("post:") &&
273-
memcmp(p, "post:", strlen("post:")) == 0)
272+
else if (plen == strlen("post:") && strstartswith(p, "post:"))
274273
mode = S_POST;
275274
else if (*s != '\0' || (*s == '\0' && !was_space)) {
276275
if (mode == S_PRE) {
@@ -351,10 +350,9 @@ static int kmod_config_add_softdep(struct kmod_config *config, const char *modna
351350
}
352351
plen = s - p;
353352

354-
if (plen == strlen("pre:") && memcmp(p, "pre:", strlen("pre:")) == 0)
353+
if (plen == strlen("pre:") && strstartswith(p, "pre:"))
355354
mode = S_PRE;
356-
else if (plen == strlen("post:") &&
357-
memcmp(p, "post:", strlen("post:")) == 0)
355+
else if (plen == strlen("post:") && strstartswith(p, "post:"))
358356
mode = S_POST;
359357
else if (*s != '\0' || (*s == '\0' && !was_space)) {
360358
if (mode == S_PRE) {

libkmod/libkmod-signature.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ bool kmod_module_signature_info(const struct kmod_file *file,
314314
if (size < (off_t)strlen(SIG_MAGIC))
315315
return false;
316316
size -= strlen(SIG_MAGIC);
317-
if (memcmp(SIG_MAGIC, mem + size, strlen(SIG_MAGIC)) != 0)
317+
if (!strstartswith(mem + size, SIG_MAGIC))
318318
return false;
319319

320320
if (size < (off_t)sizeof(struct module_signature))

0 commit comments

Comments
 (0)