From 26613dd5943bcc208b89f49a1624c18c7dee5afc Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Mon, 21 Nov 2022 15:58:46 +0100 Subject: [PATCH] Remove compiler warnings --- cmp_tool.c | 2 +- lib/rmap.c | 10 ++++++---- test/cmp_entity/test_cmp_entity.c | 2 +- test/cmp_icu/test_decmp.c | 19 ++++++++++++++++--- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cmp_tool.c b/cmp_tool.c index a306761..19213b8 100644 --- a/cmp_tool.c +++ b/cmp_tool.c @@ -55,7 +55,7 @@ static int compression(struct cmp_cfg *cfg, struct cmp_info *info); static int decompression(struct cmp_entity *ent, uint16_t *input_model_buf); /* create a default configuration for a compression data type */ -static enum cfg_default_opt {DIFF_CFG, MODEL_CFG}; +enum cfg_default_opt {DIFF_CFG, MODEL_CFG}; static int cmp_cfg_create_default(struct cmp_cfg *cfg, enum cmp_data_type data_type, enum cfg_default_opt mode); diff --git a/lib/rmap.c b/lib/rmap.c index 3164a83..113ad1e 100644 --- a/lib/rmap.c +++ b/lib/rmap.c @@ -582,12 +582,14 @@ struct rmap_pkt *rmap_pkt_from_buffer(uint8_t *buf, uint32_t len) pkt->hdr_crc = buf[RMAP_HEADER_CRC]; if (pkt->data_len) { - if (len < RMAP_DATA_START + n + pkt->data_len + 1) { /* +1 for data CRC */ - printf("buffer len is smaller than the contained RMAP packet; buf len: %" PRIu32 " bytes vs RMAP: %lu bytes needed\n", - len, RMAP_DATA_START + n + pkt->data_len); + size_t pkt_size = RMAP_DATA_START + n + pkt->data_len + 1; /* +1 for data CRC */ + + if (len < pkt_size) { + printf("buffer len is smaller than the contained RMAP packet; buf len: %" PRIu32 " bytes vs RMAP: %zu bytes needed\n", + len, pkt_size); goto error; } - if (len > RMAP_DATA_START + n + pkt->data_len + 1) /* +1 for data CRC */ + if (len > pkt_size) printf("warning: the buffer is larger than the included RMAP packet\n"); pkt->data = (uint8_t *) malloc(pkt->data_len); diff --git a/test/cmp_entity/test_cmp_entity.c b/test/cmp_entity/test_cmp_entity.c index c127a88..439222d 100644 --- a/test/cmp_entity/test_cmp_entity.c +++ b/test/cmp_entity/test_cmp_entity.c @@ -17,11 +17,11 @@ */ +#include <stdlib.h> #include <string.h> #if defined __has_include # if __has_include(<time.h>) # include <time.h> -# include <stdlib.h> # define HAS_TIME_H 1 # endif #endif diff --git a/test/cmp_icu/test_decmp.c b/test/cmp_icu/test_decmp.c index f620b29..b00c09c 100644 --- a/test/cmp_icu/test_decmp.c +++ b/test/cmp_icu/test_decmp.c @@ -20,6 +20,14 @@ #include <string.h> #include <stdlib.h> +#if defined __has_include +# if __has_include(<time.h>) +# include <time.h> +# include <unistd.h> +# define HAS_TIME_H 1 +# endif +#endif + #include "unity.h" #include "compiler.h" @@ -202,7 +210,7 @@ void test_rice_decoder(void) uint32_t code_word; unsigned int m = ~0; /* we don't need this value */ unsigned int log2_m; - unsigned int decoded_cw; + uint32_t decoded_cw; /* test log_2 to big */ code_word = 0xE0000000; @@ -271,7 +279,7 @@ void test_decode_normal(void) uint32_t decoded_value = ~0; int stream_pos, sample; /* compressed data from 0 to 6; */ - uint32_t cmp_data[] = {0x5BBDF7E0}; + uint32_t cmp_data[1] = {0x5BBDF7E0}; struct decoder_setup setup = {0}; cpu_to_be32s(cmp_data); @@ -535,7 +543,7 @@ int my_random(unsigned int min, unsigned int max) void test_imagette_random(void) { - unsigned int seed = time(NULL) * getpid(); + unsigned int seed; size_t i, s, cmp_data_size; int error; struct cmp_cfg cfg; @@ -549,6 +557,11 @@ void test_imagette_random(void) uint16_t *data, *model = NULL, *up_model = NULL, *de_up_model = NULL; /* Seeds the pseudo-random number generator used by rand() */ +#if HAS_TIME_H + seed = time(NULL) * getpid(); +#else + seed = 1; +#endif srand(seed); printf("seed: %u\n", seed); -- GitLab