[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.
This commit is contained in:
Travis Geiselbrecht
2021-06-27 00:28:58 -07:00
parent 476b750102
commit 77fa084cd0
3 changed files with 12 additions and 7 deletions

View File

@@ -21,9 +21,9 @@
#include <lk/console_cmd.h>
#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;

View File

@@ -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 \

View File

@@ -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);
}