All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: "Roland Gaudig (OSS)" <roland.gaudig-oss@weidmueller.com>
Cc: u-boot@lists.denx.de, "Marek Behún" <marek.behun@nic.cz>,
	"Simon Glass" <sjg@chromium.org>
Subject: Re: [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal
Date: Wed, 23 Jun 2021 11:43:02 +0200	[thread overview]
Message-ID: <227785.1624441382@gemini.denx.de> (raw)
In-Reply-To: <d057362e-b317-0361-92b0-b8b88ee38e3c@weidmueller.com>

Dear Roland,

In message <d057362e-b317-0361-92b0-b8b88ee38e3c@weidmueller.com> you wrote:
>
> > ...
> >> +     /* hexadecimal to decimal conversion: "setexpr name dec value" */
> >> +     if (argc == 4 && (strcmp(argv[2], "dec") == 0)) {
> >> +             w = cmd_get_data_size(argv[3], 4);
> >> +             a = get_arg(argv[3], w);
> >> +             return env_set_ulong(argv[1], a);
> >> +     }
> > 
> > Should there not be a test for 4 arguments and the third _not_ being
> > "dec" ?  Like "setexpr foo hex 42" ?
>
> Yes it's possible to add further conversion operations. But I didn't saw a
> need for hex in the first place, as hex is currently the default within

You misunderstand.  With your code, the incorect command "setexpr foo hex 42"
would not raise any error message.

Assume such a call:

	setexpr foo kjkjkjlkj 42

This should raise an error, right?


Instead of

	if (argc == 4 && (strcmp(argv[2], "dec") == 0)) {
		...
	}

you would need something like:

	if (argc == 4) {
		if strcmp((argv[2], "dec") != 0) {
			print error message
			bail our
		}
		...
	}

But see my other suggestion anyway - why add just decimal format
when using sprintf() with a format string allows for all kinds of
fancy uses?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
"Love is an ideal thing, marriage a real thing; a  confusion  of  the
real with the ideal never goes unpunished."                  - Goethe

  reply	other threads:[~2021-06-23  9:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23  8:53 [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal Roland Gaudig (OSS)
2021-06-23  9:43 ` Wolfgang Denk [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-06-23  8:20 Roland Gaudig (OSS)
2021-06-22 13:50 [PATCH v1 0/1] " roland.gaudig-oss
2021-06-22 13:50 ` [PATCH v1 1/1] " roland.gaudig-oss
2021-06-22 19:25   ` Simon Glass
2021-06-22 19:30     ` Sean Anderson
2021-06-23  0:09       ` Simon Glass
2021-06-23  6:08         ` Wolfgang Denk
2021-06-25 12:57           ` Tom Rini
2021-06-23  6:03   ` Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=227785.1624441382@gemini.denx.de \
    --to=wd@denx.de \
    --cc=marek.behun@nic.cz \
    --cc=roland.gaudig-oss@weidmueller.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.