C 参考手册

位置:首页 > C 参考手册 >错误处理 > 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__ ,且用户在包含 <stdlib.h> 前定义 __STDC_WANT_LIB_EXT1__ 为整数常量 1 才保证可用。

参数

msg - 指向描述错误的字符串的指针
ptr - 指向实现定义的对象的指针或空指针。实现定义对象的例子,是给出检测到违规的函数名和检测到违规时的行号的对象
error - 要由调用方函数返回的错误号,若它正好是返回 errno_t 的函数之一

返回值

(无)

注意

若以 ignore_handler_s 为运行时制约违规处理函数,则可通过检验边界检查函数的调用结果检测违规,这对于不同函数可能不同(非零 errno_t ,写入到输出字符串的空字符等等)。

若从不调用 set_constraint_handler_s ,则默认处理是实现定义的:它可以是 abort_handler_signore_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 standard (ISO/IEC 9899:2011):
  • K.3.6.1.3 The ignore_handler_s function (p: 606)

参阅

边界检查函数的异常中止回调
(函数)
设置边界检查函数的出错回调
(函数)