名前空間
変種
操作

ignore_handler_s

提供: cppreference.com
< c‎ | error
ヘッダ <stdlib.h> で定義
void ignore_handler_s( const char * restrict msg,

                       void * restrict ptr,
                       errno_t error

                     );
(C11以上)

この関数は他のいかなる動作も行わずに、単に呼び出し元に戻ります。

この関数を指すポインタは何もしない実行時制約違反ハンドラを確立するために set_constraint_handler_s に渡すことができます。

すべての境界チェック付き関数と同様に、 ignore_handler_s__STDC_LIB_EXT1__ が処理系によって定義されていて、 <stdlib.h> をインクルードする前にユーザが __STDC_WANT_LIB_EXT1__ を整数定数 1 に定義した場合にのみ、利用可能であることが保証されます。

目次

[編集] 引数

msg - エラーを記述する文字列を指すポインタ
ptr - 処理系定義のオブジェクトを指すポインタ、またはヌルポインタ。 処理系定義のオブジェクトの例としては、違反を検出した関数の名前や、違反が検出されたときの行番号などです
error - errno_t を返す関数で発生した場合、その関数が返そうとしているエラー

[編集] 戻り値

(なし)

[編集] ノート

ignore_handler_s が実行時制約ハンドラとして使用される場合、違反は境界付き関数の呼び出しの結果 (異なる関数に対しては異なる場合があります (非ゼロの errno_t、出力文字列の最初のバイトに書き込まれるヌル文字、など)) を調べることによって検出することができます。

set_constraint_handler_s が一度も呼ばれない場合、デフォルトのハンドラは処理系定義です。 abort_handler_signore_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 standard (ISO/IEC 9899:2011):
  • K.3.6.1.3 The ignore_handler_s function (p: 606)

[編集] 関連項目

境界チェック関数の異常終了コールバック
(関数) [edit]
境界チェック関数のエラーコールバックを設定します
(関数) [edit]