?
This document uses PHP Chinese website manual Release
在頭文件<stdlib.h>中定義 | ||
---|---|---|
void ignore_handler_s(const char * restrict msg,void * restrict ptr,errno_t error); | (自C11以來) |
該函數(shù)只是返回給調用者而不執(zhí)行任何其他操作。
可以將指向此函數(shù)的指針傳遞給set_constraint_handler_s以建立不執(zhí)行任何操作的運行時約束違規(guī)處理程序。與所有邊界檢查的函數(shù)一樣,ignore_handler_s
只有__STDC_LIB_EXT1__
在實現(xiàn)定義并且用戶在包含之前定義__STDC_WANT_LIB_EXT1__
為整數(shù)常量時1
才能保證可用<stdlib.h>
。
msg | - | 指向描述錯誤的字符串的指針 |
---|---|---|
ptr | - | 指向實現(xiàn)定義的對象或空指針的指針。實現(xiàn)定義對象的示例是對象,該對象給出檢測到違規(guī)的函數(shù)的名稱以及檢測到違規(guī)時的行號 |
error | - | 調用函數(shù)返回的錯誤,如果它恰好是返回errno_t的函數(shù)之一 |
(none).
如果ignore_handler_s
用作運行時約束處理程序,則可以通過檢查邊界檢查函數(shù)調用的結果來檢測違規(guī)情況,這些函數(shù)調用對于不同的函數(shù)可能不同(將非零errno_t
空字符寫入輸出字符串的第一個字節(jié)等)。
如果set_constraint_handler_s
是從來不叫,默認的處理程序是實現(xiàn)定義的:它可能是abort_handler_s
,ignore_handler_s
或其他一些實現(xiàn)定義的處理程序。
#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 = 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 your software's vendor to get more help.Aborted
C11標準(ISO/IEC 9899:2011):
K.3.6.1.3 ignore_handler_s函數(shù)(p:606)
abort_handler_s(C11) | 取消對邊界檢查函數(shù)的回調(函數(shù)) |
---|---|
set_constraint_handler_s(C11) | 為邊界檢查函數(shù)(函數(shù))設置錯誤回調 |