safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
memset_s.c File Reference
#include "safe_mem_lib.h"
+ Include dependency graph for memset_s.c:

Functions

EXPORT errno_t memset_s (void *dest, rsize_t dmax, int value, rsize_t n)
 Sets the first n bytes starting at dest to the specified value, but maximal dmax bytes. More...
 

Function Documentation

◆ memset_s()

EXPORT errno_t memset_s ( void *  dest,
rsize_t  dmax,
int  value,
rsize_t  n 
)

Sets the first n bytes starting at dest to the specified value, but maximal dmax bytes.

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.7.4.1 The memset_s function (p: 621-622) http://en.cppreference.com/w/c/string/byte/memset
  • ISO/IEC JTC1 SC22 WG14 N1172, Programming languages, environments and system software interfaces, Extensions to the C Library, Part I: Bounds-checking interfaces
Parameters
[out]destpointer to memory that will be set to the value
[in]dmaxmaximum number of bytes to be written
[in]valuebyte value to be written
[in]nnumber of bytes to be set
Precondition
dest shall not be a null pointer.
dmax and n shall not be greater than RSIZE_MAX_MEM.
value shall not be greater than 255.
dmax may not be smaller than n.
Without C11 dmax and n shall not be 0
Note
The behavior is undefined if the size of the character array pointed to by dest < count <= dmax; in other words, an erroneous value of dmax does not expose the impending buffer overflow.
C11 uses RSIZE_MAX, not RSIZE_MAX_MEM.
C11 returns 0 when n = ZERO.
Returns
If there is a runtime-constraints violation, and if dest is not a null pointer, and if dmax is not larger than RSIZE_MAX_MEM, then, before reporting the runtime-constraints violation, memset_s() copies dmax bytes to the destination.
Return values
EOKwhen operation is successful
ESNULLPwhen dest is NULL pointer (EINVAL with C11)
ESZEROLwhen n = ZERO (unless C11)
ESLEMAXwhen dmax/n > RSIZE_MAX_MEM or value > 255
ESNOSPCwhen dmax < n
See also
memset16_s(), memset32_s()