set_constraint_handler_s, constraint_handler_t
|
ヘッダーで定義
<stdlib.h>
|
||
|
constraint_handler_t set_constraint_handler_s
(
constraint_handler_t handler
)
;
|
(1) | (C11以降) |
|
typedef
void
(
*
constraint_handler_t
)
(
const
char
*
restrict
msg,
void
*
restrict
ptr,
|
(2) | (C11以降) |
set_constraint_handler_s
が呼び出されない場合、デフォルトハンドラは実装定義です:
abort_handler_s
、
ignore_handler_s
、
またはその他の実装定義ハンドラである可能性があります。
すべての境界チェック付き関数と同様に、
set_constraint_handler_s
および
constraint_handler_t
は、実装によって
__STDC_LIB_EXT1__
が定義されており、かつユーザーが
<stdlib.h>
をインクルードする前に
__STDC_WANT_LIB_EXT1__
を整数定数
1
に定義した場合にのみ利用可能であることが保証されます。
目次 |
パラメータ
| handler | - |
constraint_handler_t
型の関数へのポインタ、またはnullポインタ
|
| msg | - | エラーを説明する文字列へのポインタ |
| ptr | - | 実装定義のオブジェクトへのポインタ、またはnullポインタ。実装定義のオブジェクトの例としては、違反を検出した関数名や違反が検出された行番号を提供するオブジェクトがある |
| error | - |
呼び出し元関数が返そうとしているエラー(
errno_t
を返す関数のいずれかである場合)
|
戻り値
以前にインストールされたランタイム制約ハンドラへのポインタ。(注: set_constraint_handler_s ( NULL ) を呼び出すとシステムデフォルトハンドラが設定されるため、このポインタがnullポインタになることは決してありません)。
例
#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
参考文献
- C23規格 (ISO/IEC 9899:2024):
-
- K.3.6/2 constraint_handler_t (p: TBD)
-
- K.3.6.1.1 set_constraint_handler_s関数 (p: TBD)
- C17規格 (ISO/IEC 9899:2018):
-
- K.3.6/2 constraint_handler_t (p: TBD)
-
- K.3.6.1.1 set_constraint_handler_s関数 (p: TBD)
- C11 standard (ISO/IEC 9899:2011):
-
- K.3.6/2 constraint_handler_t (p: 604)
-
- K.3.6.1.1 The set_constraint_handler_s function (p: 604-605)
関連項目
|
(C11)
|
境界チェック関数用のアボートコールバック
(関数) |
|
(C11)
|
境界チェック関数用の無視コールバック
(関数) |