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 9286BC48BC2 for ; Wed, 23 Jun 2021 09:43:14 +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 7B1E56113B for ; Wed, 23 Jun 2021 09:43:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7B1E56113B 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 2C4EB829C0; Wed, 23 Jun 2021 11:43:11 +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=1624441391; bh=ub8HQQUdGgmTWfI/XhuI+pbN0QmtWt7JLT7HcM73zpY=; h=To:cc:From:Subject:In-reply-to:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nne5y4Le5JedoyBmfB/o2bZgQie/ckGV8szhAx4tW5rmt4xG3fTCnsoRf6KHHbpPJ tZ2V1fNCRK8SuoDAhbKFiPPwhNXC+DLnukKdPrg4Eiv6DdkWEgldDt/GqeJ9xOb53N YUwXHBY4vHC1PHiTf5jNCarpIT/dm/FWMvWPKqzwzQq3DyOpAU92rSrfnR+vMdE2/R 7dndZPwz/HdHi7GLxabdDQcQipcmfcdRvb0+nIHSibXZ9pswXeIZYEH08AneBwQmlb zA47lg0u/w1/YgYiFcZviqXeWxLip99OyJ3TiERJQOkLr4ZqERMIVnWJmsakTlW53E 6D+DpGhmH6tDg== 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 9EA48829B5 for ; Wed, 23 Jun 2021 11:43:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624441389; bh=ub8HQQUdGgmTWfI/XhuI+pbN0QmtWt7JLT7HcM73zpY=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=a1NCP/DnTUqxBLDpAvKyaV61z6LPZwNdRVqO+R3RGOnEvieM4ywqxPjbGZpB6nuI0 v3XhV4fqgPwLDXkE8nNaUIZbeO8fbHPS+kqJinQNMyvFpMRMTVm8Etf4vGp4/+FaNm KtMK/q7ytGbkYIwN5yBCYJXv8SZRmXdEmsfhbNSRlCQsjufwLyo+IH9g4XrItYG+Xg JQXa/P15X+LtJt3zL0v4wyxEyoOcIXaDorjbaIZWMPijyE3VXfDNywySQUZst87Qbc k3r3LDib8j5Zm5wDSdHMHDPbhLn38Svc2Q6j4G7NTLhMLS5Gi9YvnhjUedxL0xYaVF S/GvgVxNFekNg== Received: by janitor.denx.de (Postfix, from userid 108) id 584D3A0262; Wed, 23 Jun 2021 11:43:09 +0200 (CEST) Received: from gemini.denx.de (gemini.denx.de [10.4.0.2]) by janitor.denx.de (Postfix) with ESMTPS id 426B8A0163; Wed, 23 Jun 2021 11:43:03 +0200 (CEST) Received: from gemini.denx.de (localhost [IPv6:::1]) by gemini.denx.de (Postfix) with ESMTP id C438A24011D; Wed, 23 Jun 2021 11:43:02 +0200 (CEST) To: "Roland Gaudig (OSS)" cc: u-boot@lists.denx.de, =?UTF-8?Q?Marek_Beh=c3=ban?= , Simon Glass From: Wolfgang Denk Subject: Re: [PATCH v1 1/1] cmd: setexpr: add dec operation for converting variable to decimal MIME-Version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8bit In-reply-to: References: Comments: In-reply-to "Roland Gaudig (OSS)" message dated "Wed, 23 Jun 2021 08:53:56 -0000." Date: Wed, 23 Jun 2021 11:43:02 +0200 Message-ID: <227785.1624441382@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 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