Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3541954ybz; Mon, 20 Apr 2020 05:00:48 -0700 (PDT) X-Google-Smtp-Source: APiQypJi68N4jEccFfp8E/kxfMcVtkKsSRby3CevEtRBepuhZN0imRkcl/ZrjScHm6BMcIbqdbTc X-Received: by 2002:a17:906:2f03:: with SMTP id v3mr15478187eji.105.1587384048231; Mon, 20 Apr 2020 05:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587384048; cv=none; d=google.com; s=arc-20160816; b=A9k+kUFIMkPpBDZt+gZ6O+vr4cyS/vePqHL3Gn/IAxEOClboRDycBrhKsFGWw+4SIt MrdxTc00QY4FkvF65CZ5F9lxy7sdKG1YiTGyUdQrOwgGDwRHibPgMeErDP+Dzt4BAlFF Aj4oRZXXZHpzL+0lTkFqQC3VeQ5H8moGMQOzUUYzTzgbQYjPnMq/qysrTZRFaWW2zVB2 AZiZ3y6bUI0ua7LmUZHKb3MDIhb6fF4I3igiI88tMyw5mfYpw+bTjlqZMf6Sgx99YjhG LSCQXBrFgd5JirRmOieSMKyT1V7nFAx6J8vvIE58m7s2TSTtSLlymbB3+MN9qx7nqP25 l6Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A+VqqcNQbwHmfuZJhr2wxrv5V3qhVeKVnyi403pct+M=; b=tZ4n2IpEB6lYMqUgECYHA9268uUSjJoPDDDP3e3YEoUetFpNfHFOYDjjiNSSaJePuU eliqhGFDW8lXtqrJJ6qDa3byS62GnsIk4hmafbcKeDEeNRRefRr9OU1VJgQVYEUTXTdE sJx7pujBZpwbWRF3bEsFmf0JO+9o2YNS8rE/rWs8qQUa/4f+yiDxmTJoK0OQn8VgAXYh JE00kKMkvwd3qbalY7NzWqULcyfOWCZKxZxpGkkKTPbUVyXDsSRlPJFsCr0fF6xHp47L rsiu/GDQUWA6UZ97DLwfn8Lf/UOxUO5rw2/UVA2TxavhkrLsRdk1T8fBjaQ/f/X91poX 4H4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HcFHz54s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y44si382856ede.532.2020.04.20.05.00.22; Mon, 20 Apr 2020 05:00:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HcFHz54s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727084AbgDTL4e (ORCPT + 99 others); Mon, 20 Apr 2020 07:56:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:40926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727060AbgDTL4c (ORCPT ); Mon, 20 Apr 2020 07:56:32 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3927B20724; Mon, 20 Apr 2020 11:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587383792; bh=x2bxmbLQo9yIfGe84D//e+h0jAZ+3g+7DMOCer40Rbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HcFHz54szT8o/f/rIBIm/nZXPpPjgL5l05r0Rxpxm8cg7y90KHcRFcAnUL4E/6Zg1 6sgc0YGKbIIo0OmxNq3unlgg2egK/76Ce0hEhsXQu6O8DNXw5cxJ4DPHhheJ01DFv+ /T/hGTPzOqdQDJSDxtie2A21cnngQ6Adi2Je7vMc= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, He Zhe , Steven Rostedt , Tzvetomir Stoyanov , hewenliang4@huawei.com, Arnaldo Carvalho de Melo Subject: [PATCH 43/60] tools lib traceevent: Take care of return value of asprintf Date: Mon, 20 Apr 2020 08:52:59 -0300 Message-Id: <20200420115316.18781-44-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200420115316.18781-1-acme@kernel.org> References: <20200420115316.18781-1-acme@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: He Zhe According to the API, if memory allocation wasn't possible, or some other error occurs, asprintf will return -1, and the contents of strp below are undefined. int asprintf(char **strp, const char *fmt, ...); This patch takes care of return value of asprintf to make it less error prone and prevent the following build warning. ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: He Zhe Reviewed-by: Steven Rostedt (VMware) Cc: Tzvetomir Stoyanov Cc: hewenliang4@huawei.com Link: http://lore.kernel.org/lkml/1582163930-233692-1-git-send-email-zhe.he@windriver.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/traceevent/parse-filter.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c index 20eed719542e..c271aeeb227d 100644 --- a/tools/lib/traceevent/parse-filter.c +++ b/tools/lib/traceevent/parse-filter.c @@ -1958,7 +1958,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a default: break; } - asprintf(&str, val ? "TRUE" : "FALSE"); + if (asprintf(&str, val ? "TRUE" : "FALSE") < 0) + str = NULL; break; } } @@ -1976,7 +1977,8 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a break; } - asprintf(&str, "(%s) %s (%s)", left, op, right); + if (asprintf(&str, "(%s) %s (%s)", left, op, right) < 0) + str = NULL; break; case TEP_FILTER_OP_NOT: @@ -1992,10 +1994,12 @@ static char *op_to_str(struct tep_event_filter *filter, struct tep_filter_arg *a right_val = 0; if (right_val >= 0) { /* just return the opposite */ - asprintf(&str, right_val ? "FALSE" : "TRUE"); + if (asprintf(&str, right_val ? "FALSE" : "TRUE") < 0) + str = NULL; break; } - asprintf(&str, "%s(%s)", op, right); + if (asprintf(&str, "%s(%s)", op, right) < 0) + str = NULL; break; default: @@ -2011,7 +2015,8 @@ static char *val_to_str(struct tep_event_filter *filter, struct tep_filter_arg * { char *str = NULL; - asprintf(&str, "%lld", arg->value.val); + if (asprintf(&str, "%lld", arg->value.val) < 0) + str = NULL; return str; } @@ -2069,7 +2074,8 @@ static char *exp_to_str(struct tep_event_filter *filter, struct tep_filter_arg * break; } - asprintf(&str, "%s %s %s", lstr, op, rstr); + if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0) + str = NULL; out: free(lstr); free(rstr); @@ -2113,7 +2119,8 @@ static char *num_to_str(struct tep_event_filter *filter, struct tep_filter_arg * if (!op) op = "<="; - asprintf(&str, "%s %s %s", lstr, op, rstr); + if (asprintf(&str, "%s %s %s", lstr, op, rstr) < 0) + str = NULL; break; default: @@ -2148,8 +2155,9 @@ static char *str_to_str(struct tep_event_filter *filter, struct tep_filter_arg * if (!op) op = "!~"; - asprintf(&str, "%s %s \"%s\"", - arg->str.field->name, op, arg->str.val); + if (asprintf(&str, "%s %s \"%s\"", + arg->str.field->name, op, arg->str.val) < 0) + str = NULL; break; default: @@ -2165,7 +2173,8 @@ static char *arg_to_str(struct tep_event_filter *filter, struct tep_filter_arg * switch (arg->type) { case TEP_FILTER_ARG_BOOLEAN: - asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE"); + if (asprintf(&str, arg->boolean.value ? "TRUE" : "FALSE") < 0) + str = NULL; return str; case TEP_FILTER_ARG_OP: -- 2.21.1