Skip to content

Commit

Permalink
Try new memset_safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian LALU committed Dec 20, 2024
1 parent ee81c91 commit 4cc9734
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions interface/core/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,17 @@ namespace hud
* @param value The value to be set in the buffer.
* @return Pointer to the buffer `destination`.
*/
static HD_FORCEINLINE void *set_safe(void *destination, const usize size, const u8 value) noexcept
static HD_FORCEINLINE void *set_safe(volatile void *destination, const usize size, const u8 value) noexcept
{
// The behavior is undefined if destination is a null pointer.
check(destination != nullptr);
memset(destination, value, size);
return memset((void *)destination, value, size);
// Prevent compiler from removing the memset
// Add a volatile pointer to the memory and reaffect it to destination
// This prevent memset to be remove if the user don't use return value
volatile unsigned char *p = (volatile unsigned char *)destination;
destination = (void *)p;
return destination;
// volatile unsigned char *p = (volatile unsigned char *)destination;
// destination = (void *)p;
// return destination;
}

static constexpr void set_safe(u8 *destination, const usize size, const u8 value) noexcept
Expand Down

0 comments on commit 4cc9734

Please sign in to comment.