abort_handler_s
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <stdlib.h> で定義
|
||
void abort_handler_s( const char * restrict msg, void * restrict ptr, errno_t error ); |
(C11以上) | |
msg の指す文字列を含まなければならない処理系定義のメッセージを stderr に書き込み、 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、または何らかの他の処理系定義のハンドラになるかもしれません。
例
Run this code
#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.2 The abort_handler_s function (p: 605)
関連項目
(C11) |
境界チェック関数の無視コールバック (関数) |
| 境界チェック関数のエラーコールバックを設定します (関数) |