cbase 1.46.11
C/C++ Static Template
Loading...
Searching...
No Matches
Memory Safety

Wrappers around string.h functions that force sizeof() safety. More...

Macros

#define MEM_ZERO(ptr, size)
 Wraps memset to explicitly write 0s to a block of memory.
#define MEM_ZERO_STRUCT(ptr)
 Zeroes out a struct securely using the pointer's inner type size.
#define MEM_ZERO_ARRAY(arr)
 Zeroes out a static array securely using the array's full size.
#define MEM_COPY(dst, src, size)
 Wraps memmove for standard memory copying.
#define MEM_COPY_STRUCT(dst, src)
 Safely copies data from one struct pointer to another.
#define MEM_COPY_ARRAY(dst, src)
 Safely copies data from one static array to another.

Detailed Description

Wrappers around string.h functions that force sizeof() safety.

Macro Definition Documentation

◆ MEM_COPY

#define MEM_COPY ( dst,
src,
size )
Value:
memmove((dst), (src), (size))

Wraps memmove for standard memory copying.

Definition at line 410 of file base_macros.h.

◆ MEM_COPY_ARRAY

#define MEM_COPY_ARRAY ( dst,
src )
Value:
MEM_COPY((dst), (src), MIN(sizeof(dst), sizeof(src)))
#define MEM_COPY(dst, src, size)
Wraps memmove for standard memory copying.
#define MIN(a, b)
Returns the minimum of two values (Standard C fallback).

Safely copies data from one static array to another.

Note
Automatically clamps the copy size to the smallest array to prevent overflows.
Parameters
dstDestination array.
srcSource array.

Definition at line 426 of file base_macros.h.

◆ MEM_COPY_STRUCT

#define MEM_COPY_STRUCT ( dst,
src )
Value:
MEM_COPY((dst), (src), MIN(sizeof(*(dst)), sizeof(*(src))))

Safely copies data from one struct pointer to another.

Note
Automatically clamps the copy size to the smallest of either struct to prevent overflows.
Parameters
dstPointer to the destination struct.
srcPointer to the source struct.

Definition at line 418 of file base_macros.h.

◆ MEM_ZERO

#define MEM_ZERO ( ptr,
size )
Value:
memset((ptr), 0, (size))

Wraps memset to explicitly write 0s to a block of memory.

Definition at line 395 of file base_macros.h.

◆ MEM_ZERO_ARRAY

#define MEM_ZERO_ARRAY ( arr)
Value:
MEM_ZERO((arr), sizeof(arr))
#define MEM_ZERO(ptr, size)
Wraps memset to explicitly write 0s to a block of memory.

Zeroes out a static array securely using the array's full size.

Parameters
arrThe statically allocated array.

Definition at line 407 of file base_macros.h.

◆ MEM_ZERO_STRUCT

#define MEM_ZERO_STRUCT ( ptr)
Value:
MEM_ZERO((ptr), sizeof(*(ptr)))

Zeroes out a struct securely using the pointer's inner type size.

Parameters
ptrPointer to the struct.

Definition at line 401 of file base_macros.h.