From patchwork Wed Mar 24 18:07:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 1457989 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=LMgZl+FP; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F5GS11lJNz9sSC for ; Thu, 25 Mar 2021 05:08:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 766793861971; Wed, 24 Mar 2021 18:07:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 766793861971 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616609278; bh=jTrrD9+kLrwR0vDtZZKhQOg6d5qVGsNvDn/QiPl9YyY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=LMgZl+FPGr9Y1zXPmaKVkAiVer/OtGQYkE640cq6J1IoxoYnH7YH3i7WEPGwIVzOB Dicp0QgpB++PImgv/92UgbegarsFSAXOTyXygNSDfbVAf5pkwsmPlf81mjqh2VI6Wy 7hTdPCi6Gyhob6ipjIeWFbIk7Q7GADc9tbs530gU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 475763861971 for ; Wed, 24 Mar 2021 18:07:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 475763861971 Received: by mail-wm1-x32e.google.com with SMTP id t5-20020a1c77050000b029010e62cea9deso1734716wmi.0 for ; Wed, 24 Mar 2021 11:07:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jTrrD9+kLrwR0vDtZZKhQOg6d5qVGsNvDn/QiPl9YyY=; b=ocKEgG3irxM0vYtRoSEO8lhuEH7kWZb8h5TohkLd4Z483stV8snibIO/a+eFQv2rKm 8cdt0N4YXBbMAnmd0/CrWFtDw81yhiLlbktFd6w9OvSI1gmre5j3OqloFQSKgxGZVbLn /OfGwLMBU71bxRWEt0dPaCUJCB90P2zNSpCdpXoMtueW2HuDtHMJxxy8hMguvTS0cOCa u/T87oX2x8ldJnSDzHsmHvtn8neRqHlZloLPpZ5fmS01XNlvxAOuZhR2u1Pe988WEqX2 wsHkXjQxxo/Ouci5/P7c+YBiV4HjthSnrilK5SZuqNoBYKsqs5NZFV0IhaCztE/x5U+I rEqA== X-Gm-Message-State: AOAM531USo8QSZBFbekxNWfeB9X2i/5a5OM5sKQJtsYLkVfUztRrKg6F PeROBC8D+oX/XJmrxfhM8hkPeZOlPBk= X-Google-Smtp-Source: ABdhPJxtgluNFAN3b8SaW8maS5Bj2y4ss8EwlKEIn4JcPOhCAI+LnWFDYMF2MSh4VZI+lKy3PIyFmQ== X-Received: by 2002:a05:600c:203:: with SMTP id 3mr4106879wmi.88.1616609273406; Wed, 24 Mar 2021 11:07:53 -0700 (PDT) Received: from localhost.localdomain ([170.253.36.171]) by smtp.googlemail.com with ESMTPSA id r14sm4180684wrw.91.2021.03.24.11.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 11:07:53 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] stdio-common/printf-prs.c: Simplify test Date: Wed, 24 Mar 2021 19:07:19 +0100 Message-Id: <20210324180718.28006-1-alx.manpages@gmail.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alejandro Colomar via Libc-alpha From: Alejandro Colomar Reply-To: Alejandro Colomar Cc: Alejandro Colomar Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The test was being repeated for all the remaining code in the for loop. Test once, and 'continue' to next iteration if necessary, so that the following code can assume that the necessary condition is met. Minor changes: fix some mixed tabs & spaces to use spaces only. Signed-off-by: Alejandro Colomar --- stdio-common/printf-prs.c | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/stdio-common/printf-prs.c b/stdio-common/printf-prs.c index 1d4e00553d..a0c5c5487b 100644 --- a/stdio-common/printf-prs.c +++ b/stdio-common/printf-prs.c @@ -72,30 +72,32 @@ parse_printf_format (const char *fmt, size_t n, int *argtypes) /* Parse this spec. */ nargs += __parse_one_specmb (f, nargs, &spec, &max_ref_arg); + if ((size_t) spec.width_arg >= n) + continue; + /* If the width is determined by an argument this is an int. */ - if (spec.width_arg != -1 && (size_t) spec.width_arg < n) - argtypes[spec.width_arg] = PA_INT; + if (spec.width_arg != -1) + argtypes[spec.width_arg] = PA_INT; /* If the precision is determined by an argument this is an int. */ - if (spec.prec_arg != -1 && (size_t) spec.prec_arg < n) - argtypes[spec.prec_arg] = PA_INT; - - if ((size_t) spec.data_arg < n) - switch (spec.ndata_args) - { - case 0: /* No arguments. */ - break; - case 1: /* One argument; we already have the type. */ - argtypes[spec.data_arg] = spec.data_arg_type; - break; - default: - /* We have more than one argument for this format spec. We must - call the arginfo function again to determine all the types. */ - (void) (*__printf_arginfo_table[spec.info.spec]) - (&spec.info, n - spec.data_arg, &argtypes[spec.data_arg], - &spec.size); - break; - } + if (spec.prec_arg != -1) + argtypes[spec.prec_arg] = PA_INT; + + switch (spec.ndata_args) + { + case 0: /* No arguments. */ + break; + case 1: /* One argument; we already have the type. */ + argtypes[spec.data_arg] = spec.data_arg_type; + break; + default: + /* We have more than one argument for this format spec. We must + call the arginfo function again to determine all the types. */ + (void) (*__printf_arginfo_table[spec.info.spec]) + (&spec.info, n - spec.data_arg, &argtypes[spec.data_arg], + &spec.size); + break; + } } return MAX (nargs, max_ref_arg);