Namespaces
Variants

ignore_handler_s

From cppreference.net
< 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__ が定義され、かつユーザーが __STDC_WANT_LIB_EXT1__ を整数定数 1 に定義した場合にのみ利用可能であることが保証されます。 <stdlib.h> をインクルードする前に定義する必要があります。

目次

パラメータ

msg - エラーを説明する文字列へのポインタ
ptr - 実装定義のオブジェクトまたはnullポインタへのポインタ。実装定義のオブジェクトの例としては、違反を検出した関数名と違反が検出された行番号を提供するオブジェクトなどがある
error - 呼び出し元関数が返そうとしているエラー(errno_tを返す関数のいずれかである場合)

戻り値

(なし)

注記

ignore_handler_s がランタイム制約ハンドラとして使用される場合、違反は境界チェック付き関数呼び出しの結果を検査することで検出される可能性があります。この結果は関数によって異なる場合があります(非ゼロの errno_t 、出力文字列の先頭バイトへのnull文字の書き込みなど)

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 ignore_handler_s関数 (p: 606)

関連項目

境界チェック関数用の異常終了コールバック
(関数)
境界チェック関数用のエラーコールバックを設定する
(関数)