ignore_handler_s
来自 cppreference.cn
在头文件 <stdlib.h> 中定义 |
||
void ignore_handler_s( const char * restrict msg, void * restrict ptr, |
(C11 起) | |
该函数直接返回调用者,不执行任何其他操作。
可以将指向此函数的指针传递给 set_constraint_handler_s,以建立一个不做任何事情的运行时约束违规处理程序。
- 与所有经过边界检查的函数一样,仅当实现定义了 __STDC_LIB_EXT1__ 且用户在包含
<stdlib.h>
之前将 __STDC_WANT_LIB_EXT1__ 定义为整数常量 1 时,才能保证ignore_handler_s
可用。
目录 |
[编辑] 参数
msg | - | 指向描述错误的字符串的指针 |
ptr | - | 指向实现定义对象或空指针的指针。实现定义对象的示例是提供检测到违规的函数名称和检测到违规的行号的对象 |
error | - | 调用函数即将返回的错误,如果它恰好是返回 errno_t 的函数之一 |
[编辑] 返回值
(无)
[编辑] 注意
如果 ignore_handler_s
用作运行时约束处理程序,则可以通过检查经过边界检查的函数调用的结果来检测违规,这些结果对于不同的函数可能不同(非零 errno_t、输出字符串的第一个字节写入空字符等)
如果从未调用 set_constraint_handler_s
,则默认处理程序是实现定义的:它可能是 abort_handler_s、ignore_handler_s 或其他实现定义的处理程序。
[编辑] 示例
运行此代码
#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 }
可能的输出
dst = "", r = 22 abort_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 result of a bug present in the software. Please reach out to your software's vendor to get more help. Aborted
[编辑] 参考
- C11 标准 (ISO/IEC 9899:2011)
- K.3.6.1.3 ignore_handler_s 函数 (p: 606)
[编辑] 另请参阅
(C11) |
边界检查函数的中止回调。 (函数) |
为边界检查函数设置错误回调。 (函数) |