abort_handler_s
From cppreference.com
| ヘッダー <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__ が定義され、ユーザーが<stdlib.h>をインクルードする前に __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) |
境界検査付き関数のignoreコールバック (関数) |
| 境界検査付き関数のエラーコールバックを設定する (関数) |