From patchwork Mon Jul 12 21:55:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 473147 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp3347895jao; Mon, 12 Jul 2021 15:02:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuqGi41bdhqV9xzJGwsIeuF9/tgDl3rz8BAVtOyBa54K8YtVayIA4Ft/MXPW5af3dBUUWa X-Received: by 2002:a67:f854:: with SMTP id b20mr1898233vsp.32.1626127373769; Mon, 12 Jul 2021 15:02:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626127373; cv=none; d=google.com; s=arc-20160816; b=00u9G9C0L49ZusXs5z/7isD4eu2/+2b8IdK7xeX8qWd5MDWc5/4NYvt5rAa/G4UC2w FPFt1x0S2mgl6Wa7MWvkjKNFW4nNPeqB4WSC+lEs/Rk7LiNgfV8gqc4de4t4JwwY405I wRAgkc8u32UVXiedxzRRT/i2HwPRLhdfJI464dxeXJ9f6UPcVYs7bZLKwYffYCYVdltD 3qLF7G0FU1kkWrup58mmw7oGpjn2O6HfIcwQmNnioORS8l0PdXwrxilfwTZ/aLJJvkk/ MGqCUETBdd0Ilv8t0ZGDA0VkRhP0x+LkJMT/zRWl8BQ36U1RyB8Nj1GZe9gvzHJbz85+ 2Plw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=V4NDEP6+OPN3RZuxFlIMW6dNi+3smAct890DuJEN23o=; b=m3yT7QhfH4O4QL1Ux4ZvBe1t9PbaTtL55/6v2mHhZtpA/7Kv6FqzQfhQ1PYc6IuTZo br3fyTrhybDj4RV8RXUsqv0vFTlKsSNGKsuqEWHPwLaMlK7PoeXScNOzwTVkXSS5ySjs nkzmtk11Wbkf2r9W7jiA0MHQIvqjD/9gtu5cIiMxr7zx72pm5r4RdpzvATntqaNd4xqF HGBkYbpi++yWp4xTrCJ9QBhjsfxWT/6nEDQlwDkwn+YFR4i8+emg3CQXCabXPqJbkSkA MVWlkDskjwVx52TMdjcrDlEGHt4LaZ4AxiO3kxk3rl1Xx9OmFy4q496jgAWQrP3RbTTj UMWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QPmfAvba; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i26si4191543vsj.180.2021.07.12.15.02.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Jul 2021 15:02:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QPmfAvba; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m340r-0003Ip-51 for patch@linaro.org; Mon, 12 Jul 2021 18:02:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m33tv-0000ac-PN for qemu-devel@nongnu.org; Mon, 12 Jul 2021 17:55:43 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:52956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m33ts-0006rY-RI for qemu-devel@nongnu.org; Mon, 12 Jul 2021 17:55:43 -0400 Received: by mail-pj1-x102a.google.com with SMTP id bt15so5844225pjb.2 for ; Mon, 12 Jul 2021 14:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V4NDEP6+OPN3RZuxFlIMW6dNi+3smAct890DuJEN23o=; b=QPmfAvbabUtgs8i44opkL8TVTPxkjd+6w/WNlclRMTNopwLELhWfrIQnTh1nYeJObF V4R7GLhDRbBpA72gjlYNen8xeSV0TN+u0s9mD6PIAbBbwYqMxf5Zb2vs25DcBqmteK+a FxWM1XzLrJ4Lo1zesZO3YuRbRn16BEveJQ0IHstqgc3V+lLhBT6KgOL8HTQeG0TeLSUO iZbrtW7AonexFnLAjAhmzhDdxNjVidDBnIE30Y6cmCBSDXC4n2d41ijoBR8Jz7TR4MBT xVUYOh9OL6/PAZE0gcflVozCc30fOY9OUUcUReXYOsjT7cGHzdMJRlPpQIy6Uu8jb22P ZCeg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=V4NDEP6+OPN3RZuxFlIMW6dNi+3smAct890DuJEN23o=; b=D2GjO8FayQ/7956L1rgmmeigzvPnaPPYoPP6j4sXQPwjfPyy+FxZ4JZkkLy36tGAwH uo4L+3ZuWeJFMEGngeF3X0D+0Xw8+zEXEROM12i242JQUcytlukDk7oyeFwvoU8GPJk4 pNhWBu9gFEWzT+i2ufkxBvLPUew8ipWu4C1FYYb/tCqrITKHGIiJfAJsr8hm5tlOsfYt BvYHuzSFRqsnnjxOQ3fMVvfzuLnbhcsmBZwz5eWEwRgXQkq9dJFkjONWj+29rWRlZdbh 2cQO7V7+VnddDys04ujp3+xRFkOZa0JHdNbs3EUQsPAIL5eer/e0IVXtxCDdpqDfyIxH 0I8w== X-Gm-Message-State: AOAM531vVTQQWrC6ByhPIibXqwP1YznNK+9vGPNkGtoj9AcWMHyQUZBw YUWD9KOpKY+rad9V3aGFT7+SGKL2tWdLvw== X-Received: by 2002:a17:90a:a087:: with SMTP id r7mr16124415pjp.84.1626126939211; Mon, 12 Jul 2021 14:55:39 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id d2sm376932pjo.50.2021.07.12.14.55.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 14:55:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/11] util/selfmap: Discard mapping on error Date: Mon, 12 Jul 2021 14:55:27 -0700 Message-Id: <20210712215535.1471256-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712215535.1471256-1-richard.henderson@linaro.org> References: <20210712215535.1471256-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" >From clang-13: util/selfmap.c:26:21: error: variable 'errors' set but not used \ [-Werror,-Wunused-but-set-variable] Quite right of course, but there's no reason not to check errors. First, incrementing errors is incorrect, because qemu_strtoul returns an errno not a count -- just or them together so that we have a non-zero value at the end. Second, if we have an error, do not add the struct to the list, but free it instead. Cc: Alex Bennée Signed-off-by: Richard Henderson --- util/selfmap.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) -- 2.25.1 diff --git a/util/selfmap.c b/util/selfmap.c index 2ec99dfdda..0178c2ff8b 100644 --- a/util/selfmap.c +++ b/util/selfmap.c @@ -23,29 +23,33 @@ GSList *read_self_maps(void) gchar **fields = g_strsplit(lines[i], " ", 6); if (g_strv_length(fields) > 4) { MapInfo *e = g_new0(MapInfo, 1); - int errors; + int errors = 0; const char *end; - errors = qemu_strtoul(fields[0], &end, 16, &e->start); - errors += qemu_strtoul(end + 1, NULL, 16, &e->end); + errors |= qemu_strtoul(fields[0], &end, 16, &e->start); + errors |= qemu_strtoul(end + 1, NULL, 16, &e->end); e->is_read = fields[1][0] == 'r'; e->is_write = fields[1][1] == 'w'; e->is_exec = fields[1][2] == 'x'; e->is_priv = fields[1][3] == 'p'; - errors += qemu_strtoul(fields[2], NULL, 16, &e->offset); + errors |= qemu_strtoul(fields[2], NULL, 16, &e->offset); e->dev = g_strdup(fields[3]); - errors += qemu_strtou64(fields[4], NULL, 10, &e->inode); + errors |= qemu_strtou64(fields[4], NULL, 10, &e->inode); - /* - * The last field may have leading spaces which we - * need to strip. - */ - if (g_strv_length(fields) == 6) { - e->path = g_strdup(g_strchug(fields[5])); + if (!errors) { + /* + * The last field may have leading spaces which we + * need to strip. + */ + if (g_strv_length(fields) == 6) { + e->path = g_strdup(g_strchug(fields[5])); + } + map_info = g_slist_prepend(map_info, e); + } else { + g_free(e); } - map_info = g_slist_prepend(map_info, e); } g_strfreev(fields);