From patchwork Mon Jul 23 13:19:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 947783 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41Z2Cc6hVPz9s29 for ; Mon, 23 Jul 2018 23:19:56 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41Z2Cc2HHTzDqv6 for ; Mon, 23 Jul 2018 23:19:56 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=thuth@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41Z2CT0BH7zDqmj for ; Mon, 23 Jul 2018 23:19:48 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C1C94021FC2; Mon, 23 Jul 2018 13:19:46 +0000 (UTC) Received: from thh440s.str.redhat.com (dhcp-200-180.str.redhat.com [10.33.200.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C662111CA17; Mon, 23 Jul 2018 13:19:45 +0000 (UTC) From: Thomas Huth To: slof@lists.ozlabs.org Date: Mon, 23 Jul 2018 15:19:44 +0200 Message-Id: <1532351984-13501-1-git-send-email-thuth@redhat.com> In-Reply-To: <20180721164652.GF16221@gate.crashing.org> References: <20180721164652.GF16221@gate.crashing.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Jul 2018 13:19:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Jul 2018 13:19:46 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Subject: [SLOF] [PATCH v2.1] romfs/tools: Silence more compiler warnings with GCC 8.1 X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" GCC 8 complains about the following usages of strncpy, too: create_crc.c:86:3: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] strncpy(uHeader.stHeader.version, pcVersion, 16); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ create_crc.c:84:3: warning: ‘strncpy’ specified bound 16 equals destination size [-Wstringop-truncation] strncpy(uHeader.stHeader.version, pcVersion, 16); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Let's work around the issue by using memcpy instead. Signed-off-by: Thomas Huth --- romfs/tools/create_crc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/romfs/tools/create_crc.c b/romfs/tools/create_crc.c index 475b184..abc373b 100644 --- a/romfs/tools/create_crc.c +++ b/romfs/tools/create_crc.c @@ -32,6 +32,11 @@ static uint64_t ui64globalHeaderSize = 0; /* flag to filter detect the header in buildDataStream() */ static int iglobalHeaderFlag = 1; +static size_t min(size_t a, size_t b) +{ + return a < b ? a : b; +} + /** * Build the file image and store it as Data Stream of bytes * calculate a first CRC for the first file and @@ -80,13 +85,13 @@ createHeaderImage(int notime) }; /* read driver info */ - if (NULL != (pcVersion = getenv("DRIVER_NAME"))) { - strncpy(stHeader.version, pcVersion, 16); - } else if (NULL != (pcVersion = getenv("USER"))) { - strncpy(stHeader.version, pcVersion, 16); - } else if (pcVersion == NULL) { - strncpy(stHeader.version, "No known user!", 16); - } + pcVersion = getenv("DRIVER_NAME"); + if (!pcVersion) + pcVersion = getenv("USER"); + if (!pcVersion) + pcVersion = "unknown"; + memcpy(stHeader.version, pcVersion, + min(strlen(pcVersion), sizeof(stHeader.version))); if (!notime) { /* read time and write it into data stream */