diff mbox

[U-Boot,RFC] common: cli_hush: avoid dead code

Message ID 1448355263-545-2-git-send-email-Peng.Fan@freescale.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Peng Fan Nov. 24, 2015, 8:54 a.m. UTC
Condition "(value == NULL && ++value == NULL)" actully will
always return false.

Instead, use condition "(value == NULL || *(value + 1) == 0)" to detect
such expression "c=". To "c=", *(value + 1) is 0, so directly return -1,
but not continue.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Cc: Rabin Vincent <rabin@rab.in>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
---
 common/cli_hush.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Nov. 24, 2015, 7:04 p.m. UTC | #1
On 24 November 2015 at 01:54, Peng Fan <Peng.Fan@freescale.com> wrote:
> Condition "(value == NULL && ++value == NULL)" actully will
> always return false.
>
> Instead, use condition "(value == NULL || *(value + 1) == 0)" to detect
> such expression "c=". To "c=", *(value + 1) is 0, so directly return -1,
> but not continue.
>
> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
> Cc: Rabin Vincent <rabin@rab.in>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>  common/cli_hush.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

> diff --git a/common/cli_hush.c b/common/cli_hush.c
> index a7cac4f..f075459 100644
> --- a/common/cli_hush.c
> +++ b/common/cli_hush.c
> @@ -2162,7 +2162,7 @@ int set_local_var(const char *s, int flg_export)
>          * NAME=VALUE format.  So the first order of business is to
>          * split 's' on the '=' into 'name' and 'value' */
>         value = strchr(name, '=');
> -       if (value == NULL && ++value == NULL) {
> +       if (value == NULL || *(value + 1) == 0) {

I suggest:

if (!value || !value[1])

but please feel free to ignore this. What you have will work.

>                 free(name);
>                 return -1;
>         }
> --
> 2.6.2
>
>
Tom Rini Dec. 6, 2015, 10:06 p.m. UTC | #2
On Tue, Nov 24, 2015 at 04:54:21PM +0800, Peng Fan wrote:

> Condition "(value == NULL && ++value == NULL)" actully will
> always return false.
> 
> Instead, use condition "(value == NULL || *(value + 1) == 0)" to detect
> such expression "c=". To "c=", *(value + 1) is 0, so directly return -1,
> but not continue.
> 
> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
> Cc: Rabin Vincent <rabin@rab.in>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Tom Rini <trini@konsulko.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/common/cli_hush.c b/common/cli_hush.c
index a7cac4f..f075459 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -2162,7 +2162,7 @@  int set_local_var(const char *s, int flg_export)
 	 * NAME=VALUE format.  So the first order of business is to
 	 * split 's' on the '=' into 'name' and 'value' */
 	value = strchr(name, '=');
-	if (value == NULL && ++value == NULL) {
+	if (value == NULL || *(value + 1) == 0) {
 		free(name);
 		return -1;
 	}