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