...
Non-Compliant Code Example (TR24731-1)
Code Block |
---|
|
constraint_handler_t handle_errors() { |
...
constraint_handler_t data; |
...
/* define what to do when error occurs */ |
...
...
...
...
set_constraint_handler(handle_errors); |
...
...
/* Returns zero on success */ |
...
errno_t function(char* dst1){ |
...
char src1[100] = "hello"; |
...
strcpy_s( dst1, sizeof(dst1), src1); |
...
/* At this point strcpy_s may have yielded |
...
an
error and handle_errors() might have returned */ |
...
...
...
Compliant Code Example (TR24731-1)
Code Block |
---|
|
constraint_handler_t handle_errors() { |
...
/* define what to do when error occurs */ |
...
...
...
...
set_constraint_handler(handle_errors); |
...
...
/* Returns zero on success */ |
...
errno_t function(char* dst1){ |
...
char src1[100] = "hello"; |
...
strcpy_s( dst1, sizeof(dst1), src1); |
...
/* since handle_errors() never returns, |
...
we only get here if strcpy_s() succeeds. */ |
...
...
...
Risk Analysis
The risk of using in-band error indicators is difficult to quantify, and is consequently given as low. However, if the use of in-band error indicators results in programmers failing or incorrectly checking status code, the consequences can be more severe.
...