firmware-utils: mksercommfw: fix compiler warnings/errors
authorPetr Štetiar <ynezz@true.cz>
Sun, 21 Jul 2019 06:09:42 +0000 (08:09 +0200)
committerPetr Štetiar <ynezz@true.cz>
Tue, 23 Jul 2019 20:07:23 +0000 (22:07 +0200)
mksercommfw.c:134:56: error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Werror=sign-compare]
string_fortified.h:106:10: error: ‘__builtin_strncpy’ output truncated before terminating nul copying 7 bytes from a string of the same length [-Werror=stringop-truncation]
string_fortified.h:106:10: error: ‘__builtin_strncpy’ output truncated before terminating nul copying 7 bytes from a string of the same length [-Werror=stringop-truncation]

Signed-off-by: Petr Štetiar <ynezz@true.cz>
tools/firmware-utils/src/mksercommfw.c

index f6f1d93f37970be0cdf94e71a5e1093b3e92c040..5343a0205a80fde6ba2af4b345b7a6d33d53c3ad 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -52,11 +53,11 @@ static int is_header = 1;
 
 struct file_info {
        char* file_name; /* name of the file */
-       char* file_data; /* data of the file in memory */
+       uint8_t* file_data; /* data of the file in memory */
        u_int32_t file_size; /* length of the file */
 };
 
-static u_int8_t getCheckSum(char* data, int len) {
+static u_int8_t getCheckSum(uint8_t* data, int len) {
        u_int8_t new = 0;
        int i;
 
@@ -79,7 +80,7 @@ static u_int8_t getCheckSum(char* data, int len) {
 static int copyToOutputBuf(struct file_info* finfo) {
        FILE* fp = NULL;
 
-       int file_sz = 0;
+       size_t file_sz = 0;
        int extra_sz;
        int hdr_pos;
        int img_pos;
@@ -236,12 +237,12 @@ int main(int argc, char* argv[]) {
 
        DBG("Filling header: %s %s %2X %s\n", hwID, hwVer, swVer, magic);
 
-       strncpy(image.file_data + hdr_offset + 0, magic, 7);
+       memcpy(image.file_data + hdr_offset, magic, 7);
        memcpy(image.file_data + hdr_offset + 7, version, sizeof(version));
-       strncpy(image.file_data + hdr_offset + 11, hwID, 34);
-       strncpy(image.file_data + hdr_offset + 45, hwVer, 10);
+       memcpy(image.file_data + hdr_offset + 11, hwID, 34);
+       memcpy(image.file_data + hdr_offset + 45, hwVer, 10);
        memcpy(image.file_data + hdr_offset + 55, &swVer, sizeof(swVer));
-       strncpy(image.file_data + hdr_offset + 63, magic, 7);
+       memcpy(image.file_data + hdr_offset + 63, magic, 7);
 
        /* calculate checksum and invert checksum */
        if (is_header) {