[PATCH 2/5] ncurses: Fix bad strncmp

Cyril Bur cyrilbur at gmail.com
Tue Mar 6 15:46:20 AEDT 2018


On Tue, 2018-03-06 at 14:32 +1030, Joel Stanley wrote:
> ui/ncurses/nc-cui.c:967:58: warning: size argument in 'strncmp' call is a comparison [-Wmemsize-comparison]
>         if (strncmp(cod->opt->id, "dummy", strlen("dummy") == 0 &&
>                                            ~~~~~~~~~~~~~~~~~~~~~^~
> ui/ncurses/nc-cui.c:967:6: note: did you mean to compare the result of 'strncmp' instead?
>         if (strncmp(cod->opt->id, "dummy", strlen("dummy") == 0 &&
>             ^
> 
> There appears to have two bonus conditions inside the length field. I
> chose to drop the  pointless strncmp(foo, bar, strlen(bar)), as this is
> equivalent to strcmp(foo, bar).

Even more in favour of this particular form of the equivalence!

> 
> Signed-off-by: Joel Stanley <joel at jms.id.au>

Reviewed-by: Cyril Bur <cyrilbur at gmail.com>

> ---
>  ui/ncurses/nc-cui.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
> index 372da1e7a13e..20a90483cd07 100644
> --- a/ui/ncurses/nc-cui.c
> +++ b/ui/ncurses/nc-cui.c
> @@ -964,8 +964,8 @@ fallback:
>  	 * If this option was faked above move the context under
>  	 * the item so it is cleaned up later in cui_plugins_remove().
>  	 */
> -	if (strncmp(cod->opt->id, "dummy", strlen("dummy") == 0 &&
> -				cod->dev->type == DEVICE_TYPE_UNKNOWN)) {
> +	if (strcmp(cod->opt->id, "dummy") == 0 &&
> +			cod->dev->type == DEVICE_TYPE_UNKNOWN) {
>  		talloc_steal(item, cod->dev);
>  		talloc_steal(item, cod->opt);
>  	}


More information about the Petitboot mailing list