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__
를 정의하고 사용자가
__STDC_WANT_LIB_EXT1__
를 정수 상수
1
으로 정의한 경우에만 사용 가능함이 보장됩니다. 이는
<stdlib.h>
를 포함하기 전에 정의되어야 합니다.
목차 |
매개변수
| handler | - |
constraint_handler_t
타입의 함수 포인터 또는 널 포인터
|
| msg | - | 오류를 설명하는 문자열에 대한 포인터 |
| ptr | - | 구현 정의 객체에 대한 포인터 또는 널 포인터. 구현 정의 객체의 예로는 위반을 감지한 함수 이름과 위반이 감지된 라인 번호를 제공하는 객체가 있음 |
| 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 표준 (ISO/IEC 9899:2011):
-
- K.3.6/2 constraint_handler_t (p: 604)
-
- K.3.6.1.1 set_constraint_handler_s 함수 (p: 604-605)
참고 항목
|
(C11)
|
경계 검사 함수를 위한 중단 콜백
(함수) |
|
(C11)
|
경계 검사 함수를 위한 무시 콜백
(함수) |