summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2025-10-11 16:50:47 +0200
committerHiFiPhile <[email protected]>2025-10-11 16:50:47 +0200
commit190237741879145088535f214e4a1a7f21eff6af (patch)
treecf6c3dd022008e46a1407fb9355e411250fd8702 /src/common
parent080ca2e5cc96ffde2820807e2e663e1c61ca5132 (diff)
parent2e29d1c60d119b2aa71e36d0c1ac2a383e333076 (diff)
Merge branch 'master' into uac1
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_common.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index 4d83974f6..023e046b8 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -35,7 +35,7 @@
// Macros Helper
//--------------------------------------------------------------------+
#define TU_ARRAY_SIZE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) )
-#define TU_FIELD_SZIE(_type, _field) (sizeof(((_type *)0)->_field))
+#define TU_FIELD_SIZE(_type, _field) (sizeof(((_type *)0)->_field))
#define TU_MIN(_x, _y) ( ( (_x) < (_y) ) ? (_x) : (_y) )
#define TU_MAX(_x, _y) ( ( (_x) > (_y) ) ? (_x) : (_y) )
#define TU_DIV_CEIL(n, d) (((n) + (d) - 1) / (d))
@@ -116,20 +116,35 @@ extern void* tusb_app_phys_to_virt(void *phys_addr);
// This is a backport of memset_s from c11
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) {
- // TODO may check if desst and src is not NULL
- if ( count > destsz ) {
+ // Validate parameters
+ if (dest == NULL) {
return -1;
}
+
+ if (count > destsz) {
+ return -1;
+ }
+
memset(dest, ch, count);
return 0;
}
// This is a backport of memcpy_s from c11
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count) {
- // TODO may check if desst and src is not NULL
- if ( count > destsz ) {
+ // Validate parameters
+ if (dest == NULL) {
return -1;
}
+
+ // For memcpy, src may be NULL only if count == 0. Reject otherwise.
+ if (src == NULL && count != 0) {
+ return -1;
+ }
+
+ if (count > destsz) {
+ return -1;
+ }
+
memcpy(dest, src, count);
return 0;
}