From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) From: Alejandro Colomar To: libc-alpha@sourceware.org Cc: Alejandro Colomar 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 Content-Transfer-Encoding: 8bit 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-List-Received-Date: Wed, 24 Mar 2021 18:07:56 -0000 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); -- 2.31.0