All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: Roland Gaudig <roland.gaudig-oss@weidmueller.com>
Cc: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>,
	Roland Gaudig <roland.gaudig@weidmueller.com>
Subject: Re: [PATCH 1/3] cmd: setexpr: add fmt format string operation
Date: Tue, 29 Jun 2021 10:41:07 +0200	[thread overview]
Message-ID: <83823.1624956067@gemini.denx.de> (raw)
In-Reply-To: <20210628151750.572837-2-roland.gaudig-oss@weidmueller.com>

Dear Roland,

In message <20210628151750.572837-2-roland.gaudig-oss@weidmueller.com> you wrote:
>
> +		if (*format == '%') {
> +			switch (*(format + 1)) {
> +			case '%':
> +				/* found '%%', not a format specifier, skip. */
> +				format++;
> +				break;
> +			case '\0':
> +				/* found '%' at end of string,
> +				 * incomplete format specifier.
> +				 */
> +				return NULL;
> +			default:
> +				/* looks like a format specifier */
> +				return format;
> +			}
> +		}

Why do you do that here?  *printf() should be clever enough to parst
the format string.

> +static int setexpr_fmt(char *name, char *format, char *value)
> +{
> +	struct expr_arg aval;
> +	int data_size;
> +	char str[MAX_STR_LEN];
> +	int fmt_len = strlen(format);
> +
> +	if (fmt_len < 2) {
> +		printf("Error: missing format string");
> +		return CMD_RET_FAILURE;
> +	}

This is an arbitrary restriction that just limits the potential use.
Please don't do this.  Maybe I want to use:

	=> setexpr foo fmt X

This should not cause problems.

> +	/* Exactly one format specifier is required */
> +	if (!first || setexpr_fmt_spec_search(first + 1)) {
> +		printf("Error: exactly one format specifier is required\n");
> +		return CMD_RET_FAILURE;
> +	}

Please get rid of this restriction.

> +	/* Search type field of format specifier */
> +	while (*first && !isalpha(*first))
> +		first++;
> +
> +	/* Test if type is supported */
> +	if (!strchr("diouxX", *first)) {
> +		printf("Error: format type not supported\n");
> +		return CMD_RET_FAILURE;
> +	}

Get rid of all these, please!


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
Man did not weave the web of life; he  is  merely  a  strand  in  it.
Whatever he does to the web, he does to himself.     - Seattle [1854]

  parent reply	other threads:[~2021-06-29  8:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 15:17 [PATCH 0/3] cmd: setexpr: add fmt format string operation Roland Gaudig
2021-06-28 15:17 ` [PATCH 1/3] " Roland Gaudig
2021-06-28 17:39   ` Rasmus Villemoes
2021-06-29  8:44     ` Wolfgang Denk
2021-06-29  8:41   ` Wolfgang Denk [this message]
2021-06-28 15:17 ` [PATCH 2/3] doc: usage: add description for setexpr command Roland Gaudig
2021-07-05 15:29   ` Simon Glass
2021-06-28 15:17 ` [PATCH 3/3] test: cmd: setexpr: add tests for format string operations Roland Gaudig
2021-07-05 15:29   ` Simon Glass
2021-06-29  8:37 ` [PATCH 0/3] cmd: setexpr: add fmt format string operation Wolfgang Denk
2021-06-29  9:41   ` Roland Gaudig (OSS)
2021-06-29 10:34     ` Marek Behun
2021-06-29 10:40     ` Wolfgang Denk
2021-06-30  8:30       ` Roland Gaudig (OSS)
2021-06-29 13:57   ` Sean Anderson
2021-06-29 15:13     ` Wolfgang Denk
2021-06-30 16:17       ` Sean Anderson
2021-06-30 17:11         ` Marek Behún
2021-07-02 10:50         ` 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=83823.1624956067@gemini.denx.de \
    --to=wd@denx.de \
    --cc=roland.gaudig-oss@weidmueller.com \
    --cc=roland.gaudig@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.