Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3830730ybf; Tue, 3 Mar 2020 13:44:44 -0800 (PST) X-Google-Smtp-Source: ADFU+vvyQEsRG3+VN6CXLsNqM0gLHzzWCJPcbIPCq1mdFFKIA1AIZdFj+eL1Io65aZrSt1jIwDgL X-Received: by 2002:aca:44b:: with SMTP id 72mr418119oie.67.1583271884509; Tue, 03 Mar 2020 13:44:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583271884; cv=none; d=google.com; s=arc-20160816; b=P1FUiJ8HVNYn70bNACbPAN2f2qixduCl9MSUPDwQjoN2wopb8aG1J70Ojn6LYYmjPI Jvj27psHSSZjit0md5QwTyzziH5bWDB5OJeSbrRKGrgOzVKqc72ZT7i8tQV5a2NwsUd6 iqaJo0ShsxOjy8Z7QKGfAXOPAkZfo3txCMgRU34+sNUZcRgMC6AFDCHXijY8/nkCiCKx YEOLn7aslIIs/I+NBSxx4OfK1EVmZszR9/mWOu6HrFFs+8AkvCla+SQmbQtetDJUSROJ 8md8tdBRJ/MuHWNt6Gk1RpZpuWtOxxIZqiV29ptaHfB95gKrdmLx8mNoQdmIF72y48Zc 9jTA== 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=fPp3bNTixuEsF4NGDhkYXmjuT44ZVuB5cfGQAJ0vixk=; b=yhpOa/eSY/4yKgU+fd2SBr2Lehxg2+B0vN1OYm4F5Kv4ztU0Epftvq7902j2eLR4Rx KbgV08RcNCCiGjGlWETsYcDXA8kOnf6QZTVnDO+HJwsBvLtvRt3kqb8uhyu2USzQPmT0 33gAr6RIUWNAGk0rckY6GsNtBmJnl2HjQKxkywO7uERBVC+pgoYt2FCnZlA06PXniqND jsDObGVID7hV4QwJziHlcChmpz5G27fsUOqELGbqDRKu5IiJRcLQmiNPl9UTsE8fsIhK VDIK6dzhwSGycR9Q72sx8FMRUgXWLzOeEPtPvdDQsRqHD/dVGseP1BRXFY99g8i5Qynn 9KFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y9dtSdKB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si8873770otc.293.2020.03.03.13.44.32; Tue, 03 Mar 2020 13:44:44 -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; dkim=pass header.i=@kernel.org header.s=default header.b=y9dtSdKB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731369AbgCCTso (ORCPT + 99 others); Tue, 3 Mar 2020 14:48:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:57880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729609AbgCCTsn (ORCPT ); Tue, 3 Mar 2020 14:48:43 -0500 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 7D5E4215A4; Tue, 3 Mar 2020 19:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583264922; bh=agBSg6xfa4NmUWzblX7S1g3hrA1NtlKGQJ5KXkt+MA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y9dtSdKBbE/nwOFKqtLLTp9Aqip0+NEzuVGv8osb3f3Ily8/HsTOy/C8hzOTBDiAJ vFFuvuNsjqRkm6MpWWVxNWt3XNUDOiAIeA8atAnsAOMhUbfOjxg2RjkftAQwTihM9G 4Z+4qsr/itALiMjo5yNZE6kYSsryx5NS5hSuyROI= 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, Arnaldo Carvalho de Melo , Adrian Hunter Subject: [PATCH 3/5] perf parse-events: Use asprintf() instead of strncpy() to read tracepoint files Date: Tue, 3 Mar 2020 16:48:25 -0300 Message-Id: <20200303194827.6461-4-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200303194827.6461-1-acme@kernel.org> References: <20200303194827.6461-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: Arnaldo Carvalho de Melo Make the code more compact by using asprintf() instead of malloc()+strncpy() which also uses less memory and avoids these warnings with gcc 10: CC /tmp/build/perf/util/cloexec.o In file included from /usr/include/string.h:495, from util/parse-events.h:12, from util/parse-events.c:18: In function ‘strncpy’, inlined from ‘tracepoint_id_to_path’ at util/parse-events.c:271:5: /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ offset [275, 511] from the object at ‘sys_dirent’ is out of the bounds of referenced subobject ‘d_name’ with type ‘char[256]’ at offset 19 [-Werror=array-bounds] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/dirent.h:61, from util/parse-events.c:5: util/parse-events.c: In function ‘tracepoint_id_to_path’: /usr/include/bits/dirent.h:33:10: note: subobject ‘d_name’ declared here 33 | char d_name[256]; /* We must not include limits.h! */ | ^~~~~~ In file included from /usr/include/string.h:495, from util/parse-events.h:12, from util/parse-events.c:18: In function ‘strncpy’, inlined from ‘tracepoint_id_to_path’ at util/parse-events.c:273:5: /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ offset [275, 511] from the object at ‘evt_dirent’ is out of the bounds of referenced subobject ‘d_name’ with type ‘char[256]’ at offset 19 [-Werror=array-bounds] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/dirent.h:61, from util/parse-events.c:5: util/parse-events.c: In function ‘tracepoint_id_to_path’: /usr/include/bits/dirent.h:33:10: note: subobject ‘d_name’ declared here 33 | char d_name[256]; /* We must not include limits.h! */ | ^~~~~~ CC /tmp/build/perf/util/call-path.o Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Link: http://lore.kernel.org/lkml/20200302145535.GA28183@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index c01ba6f8fdad..a14995835d85 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -257,21 +257,15 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) path = zalloc(sizeof(*path)); if (!path) return NULL; - path->system = malloc(MAX_EVENT_LENGTH); - if (!path->system) { + if (asprintf(&path->system, "%.*s", MAX_EVENT_LENGTH, sys_dirent->d_name) < 0) { free(path); return NULL; } - path->name = malloc(MAX_EVENT_LENGTH); - if (!path->name) { + if (asprintf(&path->name, "%.*s", MAX_EVENT_LENGTH, evt_dirent->d_name) < 0) { zfree(&path->system); free(path); return NULL; } - strncpy(path->system, sys_dirent->d_name, - MAX_EVENT_LENGTH); - strncpy(path->name, evt_dirent->d_name, - MAX_EVENT_LENGTH); return path; } } -- 2.21.1