summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-10-11 16:01:55 +0700
committerGitHub <[email protected]>2025-10-11 16:01:55 +0700
commit2e29d1c60d119b2aa71e36d0c1ac2a383e333076 (patch)
tree3ae405dfd314d4288351097a65eb5ebe8feb835c /src/common
parent33b6954e7e9bb49b29e77f20007c6e1de2839212 (diff)
parentaa0fc2e08f1c2dd6f026a431e8989357fbb4c5bf (diff)
Merge pull request #3293
ESP32-S3 bulk transfer issues #3154
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_common.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index 2b095e238..6393652a3 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -109,20 +109,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;
}