From patchwork Sat Jun 22 10:03:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11011257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEFEA13AF for ; Sat, 22 Jun 2019 10:03:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E097B28BAF for ; Sat, 22 Jun 2019 10:03:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4B7828BB3; Sat, 22 Jun 2019 10:03:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66C4728BAF for ; Sat, 22 Jun 2019 10:03:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbfFVKDl (ORCPT ); Sat, 22 Jun 2019 06:03:41 -0400 Received: from mout.web.de ([212.227.17.11]:43003 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726112AbfFVKDk (ORCPT ); Sat, 22 Jun 2019 06:03:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1561197817; bh=G69plghB/lRsTRVOca7w69WcB+FnzDSEVJ5IwQuYXk0=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=mSqY9DsRjiVl+g1maSlor8ZqLgsOqePDDiuWuBRd9PyVs1PlsVtucoeSx8mNxvLtb b3iuma1apk4Zarti8/CWGbH4QAikWsmkZg98JgwwCoNia5vL841N310SI5pBOhTsX3 wQfSEtF172djrwIg9wxQHa03tAj3K1fzPCZ1/ZrM= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.23] ([79.203.26.169]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MWRzK-1i7eAF1BxC-00XfbE; Sat, 22 Jun 2019 12:03:37 +0200 Subject: [PATCH v2 2/3] config: don't multiply in parse_unit_factor() To: Junio C Hamano Cc: Johannes Schindelin via GitGitGadget , git@vger.kernel.org, Johannes Schindelin References: <9613c88849e53e00e1f7ade49c6c9056309ef0b9.1560426581.git.gitgitgadget@gmail.com> <03a68560-8058-7436-6edb-38e276a37190@web.de> <90ef3797-78a6-f6d9-443b-387c0ab7cbe7@web.de> From: =?utf-8?q?Ren=C3=A9_Scharfe?= Message-ID: <20bc9ec5-6e69-57aa-7347-4b7eaa8c8c1f@web.de> Date: Sat, 22 Jun 2019 12:03:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K1:pFMxU9s/60p/P12g3vRf414CPTUtWcqfpFNnHW5TN2ocJC/sK6b 0xnRNMDGeiIAlAleEudMojzQHo982IKudWemieJfEMhZKyB/nhmJq/DDj0WlHhkguTjj+vK bl1PyLzVY5k/w1sNrnx18itIY2rGlfHjoHDTzRA0hilBcDCwa73sWJkX627ARjYKZ9V8UCx a7qU8ekB/cm8wce40Amsw== X-UI-Out-Filterresults: notjunk:1;V03:K0:xy/twpCJokY=:QTYFjjyc9nZnZl0HwdMdAD PLOESo19tEbbs5NIEmpXmatrfbJw+D/GnIjadUru2/MMW/AT5dDR8QOAdgXSJQB10Y5KYJKj0 t5fDxpZt01+IKC1gf650NaJ/hkLcZOxlGrAAzuGy5k0IG5qgPyxizb68T4ZsGdb2wlW7jjxsE flV3+kLfNXVhi9feBGr80gKknhYPMz8+zKJ8uOlygU+0n6qa2UYKHJTXhwdiIN63jQtgvuX3I VBKbyJJxayTLDKTR4/hbkARcjpq3WYJ4kU1dKGlw7Y3IeDWsm6dXzFEWYu69b+6M/3wuILfJc aEjai6Evl4Tpaji7LP5GzX7Yw7TtbGj/D2XMH4xj4tX90IppJzLgr/cnth84Oo6raqKROP/cU ec9S4ZDxw4cn1Hkzqj24x78/xMBF6L7bEH2uw9zaHcVEVfTjMZvwTBLr72xbpUFKBSgm/EQ1f mJH1TL8oktOHMRS4JFexzd82xPW48tpiz88VJJyZz0N/zQcxhtYyWtHZNiT/nLvB578aCLXZq YobkWwescEtHY/AP9ViFJXLYv3npICVaqhDifegAvovNK1C9nVSusQil2vwjehnPSyaU0BNG7 q2zZsBcIZdVwttBb2gxikEeyqsTrIJyhKrRgkrT+3NMIcJrmXOW3friwZRuk2A+5DaCyHlS7H cgADjpFnm9JfMW8iZLYACJ5jAlY74X81MJOxEJ2dGR4s8n0SI1tHXf2dfWgiXM6q0U2A1fNrA oYh05AcDBYhgRLiipR3y1PYQy5xeDt4GSqtii6845nQ20evZ06J9MI6KkpjPN5Y4wXGza1qr+ 2G80UI8CSo3ub/MiR/Zv+koA36Ggi93sb6u+BQQZiQMo/7KURWx0ifDnJq4NgxuzWKhDlNzWX tgR3rd8QJyWV0zI8Xl/h8RKbm6E3ScD03zdfEEotsXR/xMYc//pSCLhtuz8egNCxQ68FUZE55 Lm0lLNz805ht89JQUA8MOOJI08pxe/SQ= Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP parse_unit_factor() multiplies the number that is passed to it with the value of a recognized unit factor (K, M or G for 2^10, 2^20 and 2^30, respectively). All callers pass in 1 as a number, though, which allows them to check the actual multiplication for overflow before they are doing it themselves. Ignore the passed in number and don't multiply, as this feature of parse_unit_factor() is not used anymore. Rename the output parameter to reflect that it's not about the end result anymore, but just about the unit factor. Suggested-by: Johannes Schindelin Signed-off-by: Rene Scharfe --- config.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) -- 2.22.0 diff --git a/config.c b/config.c index 3c00369ba8..a8bd1d821e 100644 --- a/config.c +++ b/config.c @@ -834,20 +834,22 @@ static int git_parse_source(config_fn_t fn, void *data, return error_return; } -static int parse_unit_factor(const char *end, uintmax_t *val) +static int parse_unit_factor(const char *end, uintmax_t *factor) { - if (!*end) + if (!*end) { + *factor = 1; return 1; + } else if (!strcasecmp(end, "k")) { - *val *= 1024; + *factor = 1024; return 1; } else if (!strcasecmp(end, "m")) { - *val *= 1024 * 1024; + *factor = 1024 * 1024; return 1; } else if (!strcasecmp(end, "g")) { - *val *= 1024 * 1024 * 1024; + *factor = 1024 * 1024 * 1024; return 1; } return 0; @@ -859,7 +861,7 @@ static int git_parse_signed(const char *value, intmax_t *ret, intmax_t max) char *end; intmax_t val; uintmax_t uval; - uintmax_t factor = 1; + uintmax_t factor; errno = 0; val = strtoimax(value, &end, 0); @@ -888,7 +890,7 @@ static int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max) if (value && *value) { char *end; uintmax_t val; - uintmax_t factor = 1; + uintmax_t factor; errno = 0; val = strtoumax(value, &end, 0);