ignore_handler_s
From cppreference.com
| ヘッダー <stdlib.h> で定義 |
||
| void ignore_handler_s( const char * restrict msg, void * restrict ptr, |
(C11 以降) | |
この関数は、他のアクションを実行せずに単に呼び出し元に返します。
この関数へのポインタは、何もしないランタイム制約違反ハンドラを設定するためにset_constraint_handler_sに渡すことができます。
- すべての境界チェック付き関数と同様に、
ignore_handler_sは、実装によって__STDC_LIB_EXT1__が定義されており、ユーザーが__STDC_WANT_LIB_EXT1__を整数定数1として定義してから<stdlib.h>をインクルードした場合にのみ、利用が保証されます。
目次 |
[編集] パラメータ
| msg | - | エラーを説明する文字列表記へのポインタ |
| ptr | - | 実装定義のオブジェクトまたはヌルポインタへのポインタ。実装定義のオブジェクトの例としては、違反を検出した関数の名前や、違反が検出されたときの行番号を示すオブジェクトがあります。 |
| error | - | 呼び出し元関数が返そうとしているエラー。もし、errno_tを返す関数のいずれかであった場合。 |
[編集] 戻り値
(なし)
[編集] 注記
ignore_handler_sをランタイム制約ハンドラとして使用する場合、境界チェック付き関数呼び出しの結果を調べることで違反が検出される可能性があります。この結果は関数ごとに異なる場合があります(非ゼロの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.3 The ignore_handler_s function (p: 606)
[編集] 関連項目
| (C11) |
境界検査付き関数のabortコールバック (関数) |
| 境界検査付き関数のエラーコールバックを設定する (関数) |