Skip to content

Commit 5ab5d52

Browse files
committed
arch: string.h: use memset_s for all bzero uses.
Safer and fixes the following GCC11 warning In file included from /home/lrg/work/sof/sof/src/include/sof/string.h:11, from /home/lrg/work/sof/sof/src/include/sof/debug/debug.h:17, from /home/lrg/work/sof/sof/src/platform/baytrail/platform.c:9: /home/lrg/work/sof/sof/src/platform/baytrail/platform.c: In function 'platform_init': /home/lrg/work/sof/sof/src/arch/xtensa/include/arch/string.h:22:9: error: 'memset' offset [0, 4095] is out of the bounds [0, 0] [-Werror=array-bounds] 22 | memset(ptr, 0, size) | ^~~~~~~~~~~~~~~~~~~~ /home/lrg/work/sof/sof/src/include/sof/lib/alloc.h:160:9: note: in expansion of macro 'arch_bzero' 160 | arch_bzero(ptr, size) | ^~~~~~~~~~ /home/lrg/work/sof/sof/src/platform/baytrail/platform.c:198:9: note: in expansion of macro 'bzero' 198 | bzero((void *)MAILBOX_BASE, MAILBOX_SIZE); | ^~~~~ Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 2b46d02 commit 5ab5d52

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/arch/xtensa/include/arch/string.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818
#define arch_memcpy(dest, src, size) \
1919
xthal_memcpy(dest, src, size)
2020

21-
#if __XCC__ && !defined(UNIT_TEST)
2221
#define arch_bzero(ptr, size) \
2322
memset_s(ptr, size, 0, size)
24-
#else
25-
#define arch_bzero(ptr, size) \
26-
memset(ptr, 0, size)
27-
#endif
2823

2924
void *xthal_memcpy(void *dst, const void *src, size_t len);
3025

test/cmocka/src/common_mocks.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ int WEAK memcpy_s(void *dest, size_t dest_size,
9090
return 0;
9191
}
9292

93+
int WEAK memset_s(void *dest, size_t size1,
94+
int c, size_t size2)
95+
{
96+
if (!dest)
97+
return -EINVAL;
98+
99+
memset(dest, c, size1);
100+
101+
return 0;
102+
}
103+
93104
int WEAK rstrlen(const char *s)
94105
{
95106
return strlen(s);

0 commit comments

Comments
 (0)