Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Non-Compliant Code Example (TR24731-1)

Code Block
bgColor#FFCCCC

constraint_handler_t handle_errors() {

...


  constraint_handler_t data;

...


  /* define what to do when error occurs */

...


  return data;

...


}

...



/*...*/

...



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 */

...



  /* ... */

...


  return 0;

...


}

Compliant Code Example (TR24731-1)

Code Block
bgColor#CCCCFF

constraint_handler_t handle_errors() {

...


  /* define what to do when error occurs */

...


  abort();

...


}

...



/*...*/

...



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. */

...



  /* ... */

...


  return 0;

...


}

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.

...