SLOF/SOURCES/slof-romfs-tools-Silence-more-compiler-warnings-with-GCC-.patch

82 lines
2.8 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From bc63c0f48746d246e0c2fb755515fa05077a3bfd Mon Sep 17 00:00:00 2001
From: Laurent Vivier <lvivier@redhat.com>
Date: Wed, 8 Aug 2018 15:11:02 +0100
Subject: [PATCH 6/6] romfs/tools: Silence more compiler warnings with GCC 8.1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
RH-Author: Laurent Vivier <lvivier@redhat.com>
Message-id: <20180808151102.11232-7-lvivier@redhat.com>
Patchwork-id: 81682
O-Subject: [RHEL-8.0 SLOF PATCH 6/6] romfs/tools: Silence more compiler warnings with GCC 8.1
Bugzilla: 1613619
RH-Acked-by: Thomas Huth <thuth@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: David Gibson <dgibson@redhat.com>
From: Thomas Huth <thuth@redhat.com>
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 <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
(cherry picked from commit d8a9354c2a351360da438826c95cf78efcaaf1b0)
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
---
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 */
--
1.8.3.1