blob: 4b17087ef82cd4f613ea34a63940981b64cc4236 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From d314f26e024aaf15bf4ab22ceb98501148d0eac8 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 7 May 2018 19:53:33 -0700
4Subject: [PATCH] Replace strncpy with memcpy
5
6gcc8 detects that strncpy is overwiritng the null terminating character
7the source strings are already initialized to 0 so memcpy would do the same
8job
9
10Fixes
11rn2903.c:153:5: error: 'strncpy' output may be truncated copying 16 bytes from a string of length 511 [-Werror=stringop-truncation]
12 strncpy(dev->hardware_eui, dev->resp_data, RN2903_MAX_HEX_EUI64);
13 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14
15Signed-off-by: Khem Raj <raj.khem@gmail.com>
16---
17 src/ecezo/ecezo.c | 2 +-
18 src/rn2903/rn2903.c | 2 +-
19 2 files changed, 2 insertions(+), 2 deletions(-)
20
21diff --git a/src/ecezo/ecezo.c b/src/ecezo/ecezo.c
22index 6a195fc1..56c6dab3 100644
23--- a/src/ecezo/ecezo.c
24+++ b/src/ecezo/ecezo.c
25@@ -488,7 +488,7 @@ int ecezo_send_command(const ecezo_context dev, char *cmd, char *buffer,
26 // our write buffer
27 char writeBuffer[ECEZO_MAX_BUFFER_LEN];
28
29- strncpy(writeBuffer, cmd, ECEZO_MAX_BUFFER_LEN);
30+ memcpy(writeBuffer, cmd, ECEZO_MAX_BUFFER_LEN-1);
31 writeBuffer[ECEZO_MAX_BUFFER_LEN - 1] = 0;
32
33 int writelen = strlen(writeBuffer);
34diff --git a/src/rn2903/rn2903.c b/src/rn2903/rn2903.c
35index f30a33ae..01a011da 100644
36--- a/src/rn2903/rn2903.c
37+++ b/src/rn2903/rn2903.c
38@@ -150,7 +150,7 @@ static rn2903_context _rn2903_postinit(rn2903_context dev,
39 rn2903_close(dev);
40 return NULL;
41 }
42- strncpy(dev->hardware_eui, dev->resp_data, RN2903_MAX_HEX_EUI64);
43+ memcpy(dev->hardware_eui, dev->resp_data, RN2903_MAX_HEX_EUI64);
44
45 return dev;
46 }
47--
482.17.0
49