safec 3.8.0
Safe C Library - ISO TR24731 Bounds Checking Interface
Loading...
Searching...
No Matches
safe_str_constraint.c File Reference
#include "safe_str_lib.h"
+ Include dependency graph for safe_str_constraint.c:

Functions

EXPORT constraint_handler_t set_str_constraint_handler_s (constraint_handler_t handler)
 The set_str_constraint_handler_s function sets the runtime-constraint handler to be handler.
 
EXPORT constraint_handler_t thrd_set_str_constraint_handler_s (constraint_handler_t handler)
 The thrd_set_str_constraint_handler_s function sets the runtime-constraint handler to a thread-local handler.
 
EXPORT void invoke_safe_str_constraint_handler (const char *restrict msg, void *restrict ptr, errno_t error)
 Invokes the currently set thread-safe or not constraint handler or the default.
 
int handle_str_bos_overflow (const char *restrict msg, char *restrict dest, const rsize_t dmax)
 
void handle_str_bos_chk_warn (const char *restrict func, char *restrict dest, const rsize_t dmax, const size_t destbos)
 
void handle_str_src_bos_chk_warn (const char *restrict func, char *restrict dest, const rsize_t smax, const size_t srcbos, const char *srcname, const char *smaxname)
 

Variables

static constraint_handler_t str_handler = NULL
 
static constraint_handler_t thrd_str_handler = NULL
 

Function Documentation

◆ set_str_constraint_handler_s()

EXPORT constraint_handler_t set_str_constraint_handler_s ( constraint_handler_t  handler)

The set_str_constraint_handler_s function sets the runtime-constraint handler to be handler.

The runtime-constraint handler is the function to be called when a library function detects a runtime-constraint violation. Only the most recent handler registered with set_str_constraint_handler_s is called when a runtime-constraint violation occurs. When the handler is called, it is passed the following arguments in the following order:

  1. A pointer to a character string describing the runtime-constraint violation.
  2. A null pointer or a pointer to an implementation defined object.
  3. If the function calling the handler has a return type declared as errno_t, the return value of the function is passed. Otherwise, a positive value of type errno_t is passed. The implementation has a default constraint handler that is used if no calls to the set_constraint_handler_s function have been made. The behavior of the default handler is implementation-defined, and it may cause the program to exit or abort. If the handler argument to set_constraint_handler_s is a null pointer, the implementation default handler becomes the current constraint handler.
Remarks
SPECIFIED IN ISO/IEC JTC1 SC22 WG14 N1172, Programming languages, environments and system software interfaces, Extensions to the C Library, Part I: Bounds-checking interfaces
See also
set_str_constraint_handler_s()

◆ thrd_set_str_constraint_handler_s()

EXPORT constraint_handler_t thrd_set_str_constraint_handler_s ( constraint_handler_t  handler)

The thrd_set_str_constraint_handler_s function sets the runtime-constraint handler to a thread-local handler.

The thrd_set_str_constraint_handler_s function behaves the same way as the set_str_constraint_handler_s function except that it sets the runtime-constraint handler to the handler only for the calling thread and for any threads that are yet to be created by the calling thread. The function has no effect on other threads in the program. The remaining effects of the two functions are identical, as are their return values.

Remarks
SPECIFIED IN ISO/IEC JTC1 SC22 WG14 N2809 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2809.pdf
See also
thrd_set_mem_constraint_handler_s()

◆ invoke_safe_str_constraint_handler()

EXPORT void invoke_safe_str_constraint_handler ( const char *restrict  msg,
void *restrict  ptr,
errno_t  error 
)

Invokes the currently set thread-safe or not constraint handler or the default.

Can be disabled via --disable-constraint-handler

Parameters
*msgPointer to the message describing the error.
*ptrPointer to aassociated data. Can be NULL.
errorThe error code encountered.

◆ handle_str_bos_overflow()

int handle_str_bos_overflow ( const char *restrict  msg,
char *restrict  dest,
const rsize_t  dmax 
)

◆ handle_str_bos_chk_warn()

void handle_str_bos_chk_warn ( const char *restrict  func,
char *restrict  dest,
const rsize_t  dmax,
const size_t  destbos 
)

◆ handle_str_src_bos_chk_warn()

void handle_str_src_bos_chk_warn ( const char *restrict  func,
char *restrict  dest,
const rsize_t  smax,
const size_t  srcbos,
const char *  srcname,
const char *  smaxname 
)

Variable Documentation

◆ str_handler

constraint_handler_t str_handler = NULL
static

◆ thrd_str_handler

constraint_handler_t thrd_str_handler = NULL
static