abort_handler_s
|
ヘッダーで定義
<stdlib.h>
|
||
|
void
abort_handler_s
(
const
char
*
restrict
msg,
void
*
restrict
ptr,
|
(C11以降) | |
実装定義のメッセージを
stderr
に書き込みます。このメッセージには
msg
が指す文字列を含める必要があり、
abort()
を呼び出します。
この関数へのポインタは、 set_constraint_handler_s に渡して、実行時制約違反ハンドラを確立するために使用できます。
-
すべての境界チェック付き関数と同様に、
abort_handler_sは、実装によって __STDC_LIB_EXT1__ が定義され、かつユーザーが __STDC_WANT_LIB_EXT1__ を整数定数 1 に定義した場合にのみ利用可能であることが保証されます。
目次 |
パラメータ
| msg | - | 標準エラーストリームに書き込まれるメッセージへのポインタ |
| ptr | - | 実装定義のオブジェクトまたはヌルポインタへのポインタ。実装定義のオブジェクトの例としては、違反を検出した関数名や違反が検出された行番号を提供するオブジェクトがある |
| error | - | 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.2 abort_handler_s関数 (p: 605)
関連項目
|
(C11)
|
境界チェック関数用の無視コールバック
(関数) |
|
(C11)
|
境界チェック関数用のエラーコールバックを設定
(関数) |