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,URIBL_BLOCKED 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 8DDA2C11F68 for ; Fri, 2 Jul 2021 10:50:23 +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 99E8061374 for ; Fri, 2 Jul 2021 10:50:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99E8061374 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 6FC67809D2; Fri, 2 Jul 2021 12:50:20 +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=1625223020; bh=yzFNlW31KQtpLSiK8ESnMFlLAmZ4UYXeLveQ9bz38ag=; h=To:cc:From:Subject:In-reply-to:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=L/Y8Zqyu72iqB4KmDEFZ3tmH0WeLzHneO4JhCdz4sh7hF0vYrhCAUMG7zA1njR6vS fGvIafYZv8FtOZeDIeAsTIKJTpwydww7b/CUebiqvA8ni+jDPbCDaOhhHu/FhB0Hkr zIzVpgbL8gNN1ZssI7mMPcZMkK2rI6dFATR95iSQrVq8V74hMO2/cof73rxczE8KSu J/gLZYW+J7TDHiUFGewtItrpBSIgIqpKhH5C6yy2QmWYU8v1tEtbhcj5LI6HeKsuX8 b2yDF/raeG+/cRuQKFesl5HnE3ic/tBDp1GNcLYuAS1wvaBA+/SUzV1brT9uPFZ032 fAJTeChweNZMA== 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 DCAB681E14 for ; Fri, 2 Jul 2021 12:50:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1625223017; bh=yzFNlW31KQtpLSiK8ESnMFlLAmZ4UYXeLveQ9bz38ag=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=pk8hDgUtrQSppK/l5vPrzOtJJ03AyqF+ULaHf2EH+eNZhQrPeKmYaHuKoZ3tO0Xbc GtQS8KKx/kNOGE7lijYYzhZ8b0WXPn9jRN0rEbdw9sJX2h9hADkebEO5zRWdXne/TC 8RBLOK74Yh6H6/6qcjhLYuxSfIz9BHV3MbV0cx5sbJxoAvfAOgT6nd5re6e/axIKs8 5CB2y9K2Lmfg2h2kxxiuIuRh2Jv/LSBP1VH+z1zLU0D+PXFZ6AZFJf9p/c4m6Dzq+m Xb44tsH0r8fkT4snINKO8gIbMbNhnhui3h4sau98c+DNeaTL71lKZXGMnfOT5BuUHS 4eZ63aHoI3ryw== Received: by janitor.denx.de (Postfix, from userid 108) id 8A5FBA01A3; Fri, 2 Jul 2021 12:50:17 +0200 (CEST) Received: from gemini.denx.de (gemini.denx.de [10.4.0.2]) by janitor.denx.de (Postfix) with ESMTPS id 67D5AA003B; Fri, 2 Jul 2021 12:50:02 +0200 (CEST) Received: from gemini.denx.de (localhost [IPv6:::1]) by gemini.denx.de (Postfix) with ESMTP id 0DE541E2038; Fri, 2 Jul 2021 12:50:02 +0200 (CEST) To: Sean Anderson cc: Roland Gaudig , u-boot@lists.denx.de, Simon Glass , Roland Gaudig , Alex Nemirovsky , Bin Meng , Heinrich Schuchardt , =?UTF-8?Q?Marek_Beh=c3=ban?= , Patrick Delaunay , Rayagonda Kokatanur , Robert Marko , Stefan Bosch , Weijie Gao From: Wolfgang Denk Subject: Re: [PATCH 0/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: References: <20210628151750.572837-1-roland.gaudig-oss@weidmueller.com> <83741.1624955845@gemini.denx.de> <19b6eeea-2aad-972b-aeeb-8959aab17d7a@gmail.com> <103545.1624979613@gemini.denx.de> Comments: In-reply-to Sean Anderson message dated "Wed, 30 Jun 2021 12:17:47 -0400." Date: Fri, 02 Jul 2021 12:50:02 +0200 Message-ID: <125970.1625223002@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 Sean, In message you wrote: > > >> snprintf(buf, sizeof(buf), argv[3], argc >= 4 ? argv[4] : NULL, /* etc */); > > > > Why this test on argc? If it's less than 4, argv[4] should be NULL > > anyway. > > snprintf(buf, sizeof(buf), argv[3], argc >= 4 ? argv[4] : NULL, > argc >= 5 ? argv[5] : NULL, argc >= 6 ? argv[6] : NULL, /* etc */); > > and you keep doing this until you get to whatever number of arguments > you'd like. I'm sorry, but this is not an acceptable way to implement variadic functions in C. Are you aware how va_arg works? > > Eventually the format checking can be kept out of the generic > > *printf() code; it could then be optional/configurable with the > > "fmt" option in the setexpr command. > > It's not a "checking" problem. The issue is that "123" cannot > be passed directly to %d. So you have dig into the guts of snprintf > anyway. Did you read my recommendation to have a look for example at the implementation of the printf bash builting? 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 The moral of the story is: "Don't stop to tighten your shoe laces during the Olympics 100m finals". - Kevin Jones in