| Error codes | ||||
| Error codes | ||||
| Assertions | ||||
(C11)(removed in C23) | ||||
| Bounds checking | ||||
abort_handler_s (C11) | ||||
(C11) |
Defined in header <stdlib.h> | ||
void abort_handler_s(constchar*restrict msg, void*restrict ptr, | (since C11) | |
Writes an implementation-defined message tostderr which must include the string pointed to bymsg and callsabort().
A pointer to this function can be passed toset_constraint_handler_s to establish a runtime constraints violation handler.
abort_handler_s is only guaranteed to be available if__STDC_LIB_EXT1__ is defined by the implementation and if the user defines__STDC_WANT_LIB_EXT1__ to the integer constant1 before including<stdlib.h>.Contents |
| msg | - | pointer to the message written to the standard error stream |
| ptr | - | pointer to an implementation-defined object or a null pointer. Examples of implementation-defined objects are objects that give the name of the function that detected the violation and the line number when the violation was detected |
| error | - | a positive value of type errno_t |
none; this function does not return to its caller
Ifset_constraint_handler_s is never called, the default handler is implementation-defined: it may beabort_handler_s,ignore_handler_s, or some other implementation-defined handler.
#define __STDC_WANT_LIB_EXT1__ 1#include <string.h>#include <stdio.h>#include <stdlib.h> int main(void){#ifdef __STDC_LIB_EXT1__char dst[2]; set_constraint_handler_s(ignore_handler_s);int r= strcpy_s(dst,sizeof dst,"Too long!");printf("dst =\"%s\", r = %d\n", dst, r); set_constraint_handler_s(abort_handler_s); r= strcpy_s(dst,sizeof dst,"Too long!");printf("dst =\"%s\", r = %d\n", dst, r);#endif}
Possible output:
dst = "", r = 22abort_handler_s was called in response to a runtime-constraint violation. The runtime-constraint violation was caused by the following expression in strcpy_s:(s1max <= (s2_len=strnlen_s(s2, s1max)) ) (in string_s.c:62) Note to end users: This program was terminated as a resultof a bug present in the software. Please reach out to yoursoftware's vendor to get more help.Aborted
(C11) | ignore callback for the bounds-checked functions (function)[edit] |
| set the error callback for bounds-checked functions (function)[edit] |