summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/stdio.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
new file mode 100644
index 0000000..122e678
--- /dev/null
+++ b/include/stdio.h
@@ -0,0 +1,28 @@
1#ifndef FORTIFY_STDIO_H_
2#define FORTIFY_STDIO_H_
3
4#include_next <stdio.h>
5
6#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
7
8static inline
9__attribute__ ((always_inline))
10__attribute__ ((__format__ (printf, 3, 0)))
11__attribute__ ((__nonnull__ (3)))
12int __fortify_vsnprintf(char *__restrict s, size_t n, const char *__restrict fmt, __va_list ap)
13{
14 size_t bos = __builtin_object_size(s, 0);
15
16 if (bos == (size_t)-1)
17 return vsnprintf(s, n, fmt, ap);
18 if (__builtin_constant_p(n) && n > bos)
19 __builtin_trap();
20 return vsnprintf(s, n, fmt, ap);
21}
22
23#undef vsnprintf
24#define vsnprintf(s, n, fmt, ap) __fortify_vsnprintf(s, n, fmt, ap)
25
26#endif
27
28#endif