From 77fa084cd05459a1f360a2b825e14ea6e60518e5 Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Sun, 27 Jun 2021 00:28:58 -0700 Subject: [PATCH] [warnings][gcc 11] Fix a few annoying out of bounds pointer warnings It seems to be in the case of a string op against a raw address, the compiler decides the destination object is 0 bytes long and throws a particular warning. Work around it by not using memcpy in one case and by disabling the warning in the other. Both are fairly benign code that basically operates in a hard coded way that knows the destination buffer is valid. --- app/loader/loader.c | 12 ++++++------ app/loader/rules.mk | 2 ++ app/mdebug/swd-m0sub.c | 5 ++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/loader/loader.c b/app/loader/loader.c index db5b0faa..e3b454f4 100644 --- a/app/loader/loader.c +++ b/app/loader/loader.c @@ -21,9 +21,9 @@ #include #if defined(SDRAM_BASE) -#define DOWNLOAD_BASE ((void*)SDRAM_BASE) +#define DOWNLOAD_BASE ((unsigned char*)SDRAM_BASE) #else -#define DOWNLOAD_BASE ((void*)0) +#define DOWNLOAD_BASE ((unsigned char*)0) #endif #define FNAME_SIZE 64 @@ -49,11 +49,11 @@ static download_t *make_download(const char *name) { return d; } -static void set_ram_zone(download_t *d, int slot) { - d->start = DOWNLOAD_BASE + (DOWNLOAD_SLOT_SIZE * slot); +static void set_ram_zone(download_t *d, unsigned char *spot, int slot) { + d->start = spot + (DOWNLOAD_SLOT_SIZE * slot); d->end = d->start; d->max = d->end + DOWNLOAD_SLOT_SIZE; - memset(d->start, 0, DOWNLOAD_SLOT_SIZE); + memset(spot, 0, DOWNLOAD_SLOT_SIZE); } static size_t output_result(const download_t *download) { @@ -165,7 +165,7 @@ usage: slot = argv[3].i; } - set_ram_zone(download, slot); + set_ram_zone(download, DOWNLOAD_BASE, slot); tftp_set_write_client(download->name, &tftp_callback, download); printf("ready for %s over tftp (at %p)\n", argv[2].str, download->start); return 0; diff --git a/app/loader/rules.mk b/app/loader/rules.mk index d05cb3ee..037e16df 100644 --- a/app/loader/rules.mk +++ b/app/loader/rules.mk @@ -5,6 +5,8 @@ MODULE := $(LOCAL_DIR) MODULE_SRCS += \ $(LOCAL_DIR)/loader.c \ +# disable a few warnings in gcc 11 that some of this module's code trips over +MODULE_COMPILEFLAGS += -Wno-array-bounds -Wno-stringop-overflow MODULE_DEPS := \ lib/cksum \ diff --git a/app/mdebug/swd-m0sub.c b/app/mdebug/swd-m0sub.c index 3b6f2f67..50da7d7d 100644 --- a/app/mdebug/swd-m0sub.c +++ b/app/mdebug/swd-m0sub.c @@ -113,7 +113,10 @@ void swd_init(void) { writel(M0_SUB_RST, RESET_CTRL0); writel(0x18000000, M0SUB_ZEROMAP); writel(0xffffffff, 0x18004000); - memcpy((void *) 0x18000000, zero_bin, sizeof(zero_bin)); + unsigned char *ptr = (unsigned char *)0x18000000; + for (size_t i = 0; i < sizeof(zero_bin); i++) { + ptr[i] = zero_bin[i]; + } DSB; writel(0, RESET_CTRL0); }