Namespaces
Variants
Views
Actions

Difference between revisions of "c/error/ignore handler s"

From cppreference.com
< c‎ | error
(new page; References; language links)
 
m (templatize example)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
{{title|ignore_handler_s | constraint_handler_t}}
+
{{c/title|ignore_handler_s}}
 
{{c/error/navbar}}
 
{{c/error/navbar}}
 
{{ddcl | header=stdlib.h | since=c11 |  
 
{{ddcl | header=stdlib.h | since=c11 |  
Line 8: Line 8:
 
}}
 
}}
  
A pointer to the ignore_handler_s function shall be a suitable argument to the set_constraint_handler_s function.
+
The function simply returns to the caller without performing any other action.
  
If {{tt|set_constraint_handler_s}} is never called, the default handler is implementation-defined: it may be {{lc|abort_handler_s}}, {{lc|ignore_handler_s}}, or some other implementation-defined handler.
+
A pointer to this function can be passed to {{rlp|set_constraint_handler_s}} to establish a runtime constraints violation handler that does nothing.
  
 
:As with all bounds-checked functions, {{tt|ignore_handler_s}} is only guaranteed to be available if {{c|__STDC_LIB_EXT1__}} is defined by the implementation and if the user defines {{c|__STDC_WANT_LIB_EXT1__}} to the integer constant {{c|1}} before including {{tt|<stdlib.h>}}.
 
:As with all bounds-checked functions, {{tt|ignore_handler_s}} is only guaranteed to be available if {{c|__STDC_LIB_EXT1__}} is defined by the implementation and if the user defines {{c|__STDC_WANT_LIB_EXT1__}} to the integer constant {{c|1}} before including {{tt|<stdlib.h>}}.
Line 22: Line 22:
  
 
===Return value===
 
===Return value===
none; this function simply returns to its caller
+
(none)
 +
 
 +
===Notes===
 +
If {{tt|ignore_handler_s}} is used as a the runtime constraints handler, the violations may be detected by examining the results of the bounds-checked function calls, which may be different for different functions (non-zero {{lc|errno_t}}, null character written to the first byte of the output string, etc)
 +
 
 +
If {{tt|set_constraint_handler_s}} is never called, the default handler is implementation-defined: it may be {{lc|abort_handler_s}}, {{lc|ignore_handler_s}}, or some other implementation-defined handler.
  
 
===Example===
 
===Example===
{{example}}
+
{{c/error/set_constraint_handler_example}}
  
 
===References===
 
===References===

Latest revision as of 18:11, 26 May 2015

Defined in header <stdlib.h>
void ignore_handler_s( const char * restrict msg,

                       void * restrict ptr,
                       errno_t error

                     );
(since C11)

The function simply returns to the caller without performing any other action.

A pointer to this function can be passed to set_constraint_handler_s to establish a runtime constraints violation handler that does nothing.

As with all bounds-checked functions, ignore_handler_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including <stdlib.h>.

Contents

[edit] Parameters

msg - pointer to character string that describes the error
ptr - pointer to an implementation-defined object or a null pointer. Examples of implementation-defined objects are objects that give the name of the function that detected the violation and the line number when the violation was detected
error - the error about to be returned by the calling function, if it happens to be one of the functions that return errno_t

[edit] Return value

(none)

[edit] Notes

If ignore_handler_s is used as a the runtime constraints handler, the violations may be detected by examining the results of the bounds-checked function calls, which may be different for different functions (non-zero errno_t, null character written to the first byte of the output string, etc)

If set_constraint_handler_s is never called, the default handler is implementation-defined: it may be abort_handler_s, ignore_handler_s, or some other implementation-defined handler.

[edit] Example

#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
}

Possible output:

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

[edit] References

  • C11 standard (ISO/IEC 9899:2011):
  • K.3.6.1.3 The ignore_handler_s function (p: 606)

[edit] See also

abort callback for the bounds-checked functions
(function) [edit]
set the error callback for bounds-checked functions
(function) [edit]