__builtin___*_chk
In addition to
__builtin_object_size, IBM® XL C/C++ for Linux, V13.1.5 also
supports *_chk built-in functions for some common
string operation functions; for example, __builtin___memcpy_chk is
provided for memcpy. When these built-in functions
are used with -O2 or higher optimization level, the compiler
issues a warning message if it can determine at compile time that
the object will always be overflowed; the built-in
functions are optimized to the corresponding string functions such
as memcpy when either of the following conditions
is met:
There are other checking built-in functions as described in
the following table. The corresponding library functions are called
when you use these built-in functions.
- The last argument of these functions is (size_t) -1.
- It is known at compile time that the destination object will not be overflowed.
Function | Built-in function | Prototype |
---|---|---|
memcpy | __builtin___memcpy_chk | void * __builtin___memcpy_chk (void *dest, const void *src, size_t n, size_t os); |
mempcpy | __builtin___mempcpy_chk | void * __builtin___mempcpy_chk (void *dest, const void *src, size_t n, size_t os); |
memmove | __builtin___memmove_chk | void * __builtin___memmove_chk (void *dest, const void *src, size_t n, size_t os); |
memset | __builtin___memset_chk | void * __builtin___memset_chk (void *s, int c, size_t n, size_t os); |
strcpy | __builtin___strcpy_chk | char * __builtin___strcpy_chk (char *dest, const char *src, size_t os); |
strncpy | __builtin___strncpy_chk | char * __builtin___strncpy_chk (char *dest, const char *src, size_t n, size_t os); |
stpcpy | __builtin___stpcpy_chk | char * __builtin___stpcpy_chk (char *dest, const char *src, size_t os); |
strcat | __builtin___strcat_chk | char * __builtin___strcat_chk (char *dest, const char *src, size_t os); |
strncat | __builtin___strncat_chk | char * __builtin___strncat_chk (char *dest, const char *src, size_t n, size_t os); |
Function | Built-in function | Prototype |
---|---|---|
sprintf | __builtin___sprintf_chk | int __builtin___sprintf_chk (char *s, int flag, size_t os, const char *fmt, ...); |
snprintf | __builtin___snprintf_chk | int __builtin___snprintf_chk (char *s, size_t maxlen, int flag, size_t os); |
vsprintf | __builtin___vsprintf_chk | int __builtin___vsprintf_chk (char *s, int flag, size_t os, const char *fmt,va_list ap); |
vsnprintf | __builtin___vsnprintf_chk | int __builtin___vsnprintf_chk (char *s, size_t maxlen, int flag, size_t os, const char *fmt, va_list ap); |
printf | __builtin___printf_chk | int __builtin___printf (int flag, const char *format, ...); |
vprintf | __builtin___vprintf_chk | int __builtin___vprintf (int flag, const char *format, va_list ap); |
fprintf | __builtin___fprintf_chk | int __builtin___fprintf (FILE *stream, int flag, const char *format, ...); |
vfprintf | __builtin___vfprintf_chk | int __builtin___vfprintf (FILE *stream, int flag, const char *format, va_list ap); |
Note: In the prototype of each function, the ellipsis (...)
represents an optional list of parameters. IBM XL C/C++ for Linux ignores
these optional parameters and protects all globally accessible variables.