首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ignore_handler_s

在头文件<stdlib.h>中定义

?

?

void ignore_handler_s(const char * restrict msg,void * restrict ptr,errno_t error);

?

(自C11以来)

该函数只是返回给调用者而不执行任何其他操作。

可以将指向此函数的指针传递给set_constraint_handler_s以建立不执行任何操作的运行时约束违规处理程序。与所有边界检查的函数一样,ignore_handler_s只有__STDC_LIB_EXT1__在实现定义并且用户在包含之前定义__STDC_WANT_LIB_EXT1__为整数常量时1才能保证可用<stdlib.h>

参数

msg

-

指向描述错误的字符串的指针

ptr

-

指向实现定义的对象或空指针的指针。实现定义对象的示例是对象,该对象给出检测到违规的函数的名称以及检测到违规时的行号

error

-

调用函数返回的错误,如果它恰好是返回errno_t的函数之一

返回值

(none).

注意

如果ignore_handler_s用作运行时约束处理程序,则可以通过检查边界检查函数调用的结果来检测违规情况,这些函数调用对于不同的函数可能不同(将非零errno_t空字符写入输出字符串的第一个字节等)。

如果set_constraint_handler_s是从来不叫,默认的处理程序是实现定义的:它可能是abort_handler_signore_handler_s或其他一些实现定义的处理程序。

代码语言:javascript
复制
#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
}

可能的输出:

代码语言:javascript
复制
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)

另请参阅

abort_handler_s(C11)

取消对边界检查函数的回调(函数)

set_constraint_handler_s(C11)

为边界检查函数(函数)设置错误回调

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com