From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30532C11F66 for ; Tue, 29 Jun 2021 08:41:18 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 75B4261DC8 for ; Tue, 29 Jun 2021 08:41:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75B4261DC8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EA5BA83120; Tue, 29 Jun 2021 10:41:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624956075; bh=/OcAve0SRSMQOEKDdHFjx1iacqapCTOq4L1x7MQcMe4=; h=To:cc:From:Subject:In-reply-to:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=U0SEgiibNyoKyG6eeQLqY9GKAAOUPHpqa0Om+2sXSYdm3VGbUnWyUDyi6B6plIE8T e1lIWxw+sqLGf8kMwMryiP4iIDdZOyY7GJ3/073CZ/twikCNsZFTB7LA8em38wDqEQ rHBMDTOPmwE7RKmsDGTW3mSJFOwPemt2hmKMwQ/o86AGs0BmgqveM+ehjOF+/0rtFd OYPj670/SsHIDDv4Cm7Ys9bhcWRo72K6r3/c4uSMBV/GUCh8lOaZimboT8jOIM1+aj j0en8AMLLFIbbE/cpoLWIO3ISyINrUpAWpeqSlMZjd4xJg5E394xitFtGImHjy9nBr F1/GUBwRjKKJg== Received: from janitor.denx.de (unknown [62.91.23.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: noc@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 68B6D83120 for ; Tue, 29 Jun 2021 10:41:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624956073; bh=/OcAve0SRSMQOEKDdHFjx1iacqapCTOq4L1x7MQcMe4=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=AfBwNGevKdAvrpinYkucdFzWRmtRJ6fJvgj6M2Vyt9GzBQ5B0jtN/dF1reVKUNoIl //bd+s71VvbOGUv6KQ4AU2eYWIHFUN+z9gcBiPW78YbJwCMTJjeZz/3Y9Qq3DXaYHa fHSOfGQk5H+RLBh8DAEp+Vmhs8VOvhO2zzPoPL/+4hHpql2d/TFW1VQirmBTtyZ+Xl asMDoxv/2ttIp18GS6toEIpkprykoFyp9VnbttkgsSaJIUpEu+MYVXQPSKKNUyM9VA 5+1JxMGRPZwoAIMLqSIBkAj+G3aqzaUVkn2jNZ99cWImVO5MtdqGKvzHU8pnsQTSLi Jr3co/C85BWuw== Received: by janitor.denx.de (Postfix, from userid 108) id 2399FA025B; Tue, 29 Jun 2021 10:41:13 +0200 (CEST) Received: from gemini.denx.de (gemini.denx.de [10.4.0.2]) by janitor.denx.de (Postfix) with ESMTPS id 8F76BA0165; Tue, 29 Jun 2021 10:41:07 +0200 (CEST) Received: from gemini.denx.de (localhost [IPv6:::1]) by gemini.denx.de (Postfix) with ESMTP id 5BBCF1E1DD2; Tue, 29 Jun 2021 10:41:07 +0200 (CEST) To: Roland Gaudig cc: u-boot@lists.denx.de, Simon Glass , Roland Gaudig From: Wolfgang Denk Subject: Re: [PATCH 1/3] cmd: setexpr: add fmt format string operation MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit In-reply-to: <20210628151750.572837-2-roland.gaudig-oss@weidmueller.com> References: <20210628151750.572837-1-roland.gaudig-oss@weidmueller.com> <20210628151750.572837-2-roland.gaudig-oss@weidmueller.com> Comments: In-reply-to Roland Gaudig message dated "Mon, 28 Jun 2021 15:17:48 -0000." Date: Tue, 29 Jun 2021 10:41:07 +0200 Message-ID: <83823.1624956067@gemini.denx.de> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean 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]