summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2023-02-27 10:22:53 +0700
committerGitHub <[email protected]>2023-02-27 10:22:53 +0700
commit65ac519715ea0ecace08b183f2d8730d0450affd (patch)
tree11c48c98d3afea290e460deed624a07bac0607e7 /src/common
parent73afca14eb589af84e932fdafbeeea8f8db1e771 (diff)
parente34aeb5cf69315d2d7711f0a1d040a28492d026d (diff)
Merge pull request #1852 from silvergasp/mem_s
fix: Replace device calls to memcpy with tu_memcpy_s
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tusb_common.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h
index 270339cca..957491aa9 100644
--- a/src/common/tusb_common.h
+++ b/src/common/tusb_common.h
@@ -98,6 +98,29 @@ TU_ATTR_WEAK extern void* tusb_app_phys_to_virt(void *phys_addr);
#define tu_memclr(buffer, size) memset((buffer), 0, (size))
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
+// 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) {
+ 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) {
+ return -1;
+ }
+ memcpy(dest, src, count);
+ return 0;
+}
+
+
//------------- Bytes -------------//
TU_ATTR_ALWAYS_INLINE static inline uint32_t tu_u32(uint8_t b3, uint8_t b2, uint8_t b1, uint8_t b0)
{