2014-10-31 09:32:32

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 1/2] shared/hfp: Remove reduntant check

To make this check strcmp is good enought. Not need to check len first
and then do memory compare.
---
src/shared/hfp.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 9a66ed2..0ce38cc 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -135,10 +135,7 @@ static bool match_handler_prefix(const void *a, const void *b)
const struct cmd_handler *handler = a;
const char *prefix = b;

- if (strlen(handler->prefix) != strlen(prefix))
- return false;
-
- if (memcmp(handler->prefix, prefix, strlen(prefix)))
+ if (strcmp(handler->prefix, prefix) != 0)
return false;

return true;
--
1.8.4



2014-10-31 19:13:56

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] shared/hfp: Remove reduntant check

Hi Ɓukasz,

On Friday 31 of October 2014 10:32:32 Lukasz Rymanowski wrote:
> To make this check strcmp is good enought. Not need to check len first
> and then do memory compare.
> ---
> src/shared/hfp.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 9a66ed2..0ce38cc 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -135,10 +135,7 @@ static bool match_handler_prefix(const void *a, const
> void *b) const struct cmd_handler *handler = a;
> const char *prefix = b;
>
> - if (strlen(handler->prefix) != strlen(prefix))
> - return false;
> -
> - if (memcmp(handler->prefix, prefix, strlen(prefix)))
> + if (strcmp(handler->prefix, prefix) != 0)
> return false;
>
> return true;

Applied (with typos in commit message fixed), thanks.

--
BR
Szymon Janc