Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp915957ybv; Wed, 19 Feb 2020 11:53:19 -0800 (PST) X-Google-Smtp-Source: APXvYqywvOblkQbirRxd3F8+fYXHpG31NnJKlIN/jdZKxT0Lb8eKvJUdszBfhoj4FvLwzGpSgfAn X-Received: by 2002:a05:6830:10d5:: with SMTP id z21mr21553033oto.30.1582141999608; Wed, 19 Feb 2020 11:53:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582141999; cv=none; d=google.com; s=arc-20160816; b=svVgGt38fmsaXepJ95tKuYzLg2NEk+ryFuP6yNTSqqwx4Q5wQri1N2aDV44ig7Qe0l vPpa+I4gsGzT8+J7CIHTB2MQ5N+ZX5mEOAssLsDmtdHp4x2m1iIWAW1WcnIwlpPIn8NX ugQOM46yIeWPP7CvkNQQHC1dwL4vNAhsxGjs00dJX372z3xLVkgigzfto3PEuci7M0y/ UJ0+rFpiGG4eCdJWSxW25Q58EjaDTr2TfHJ5dBm3L6V7YkC6Lje5aUnqWrb4pOLr/ff7 Z0pRxVuUhpj1rvwZsLALHNT8HGL24RrM++sytbcY8YXFLSp63KZ5CmxvvL64IeAuMZ/J 04gQ== 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:subject:cc:to:from:date; bh=mubIUYzS4Z6SjlKVw4DG0rpfDzxgOSRysfLAPqWzP0w=; b=0ezGiicgLRiyG1EkQ1hu1GDRi/YSn4H25Od4nAJ3Nu9T3dbxBXFg2xe8m/LShA2xMO LKpCaIqIQGvNXyoPzVrtN8XNNKbR1IRL30HB+S8+TCebHS7vvnxN9VE7uKjzSex4z/XY fCFqg56jk/f6Nrz43CTmeeZxBfz1uoQtwikzt5dLjoP6TYiQGuXGba3VrC6DUQIUI9dv 4YvuDg9UqzugB7AG4UMKt0MTDMy2QvZnlv2kSUZlS0ywnFeJqHY/Mr7Int1/JgFfAYvr MmukSzIg6TNTmSftnrWPd915C+ERTzo98lwoPi8FFV+8svNjbGtydAWqKSFQAo5Nya3s fOvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si368697otk.318.2020.02.19.11.53.06; Wed, 19 Feb 2020 11:53:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726734AbgBSTw6 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 19 Feb 2020 14:52:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:42486 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726651AbgBSTw6 (ORCPT ); Wed, 19 Feb 2020 14:52:58 -0500 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 67EC4208C4; Wed, 19 Feb 2020 19:52:57 +0000 (UTC) Date: Wed, 19 Feb 2020 14:52:55 -0500 From: Steven Rostedt To: Cc: , , , Subject: Re: [PATCH v2] tools lib traceevent: Take care of return value of asprintf Message-ID: <20200219145256.02a92ad8@gandalf.local.home> In-Reply-To: <1581686481-180476-1-git-send-email-zhe.he@windriver.com> References: <1581686481-180476-1-git-send-email-zhe.he@windriver.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) 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 On Fri, 14 Feb 2020 21:21:21 +0800 wrote: > 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 > --- > v2: directly check the return value without saving to a variable > > tools/lib/traceevent/parse-filter.c | 35 +++++++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 14 deletions(-) > > diff --git a/tools/lib/traceevent/parse-filter.c b/tools/lib/traceevent/parse-filter.c > index 20eed71..6cd0228 100644 > --- a/tools/lib/traceevent/parse-filter.c > +++ b/tools/lib/traceevent/parse-filter.c > @@ -274,8 +274,7 @@ find_event(struct tep_handle *tep, struct event_list **events, > sys_name = NULL; > } > > - ret = asprintf(®, "^%s$", event_name); > - if (ret < 0) > + if (asprintf(®, "^%s$", event_name) < 0) I know Arnaldo said you don't need to save the return value for the check, but let's just modify the asprintf() that needs checking, and not remove those that already save it. Thanks! -- Steve