Skip to content

Commit 265fa03

Browse files
committed
Disable pedantic checks by default
They can be re-enabled via `PEDANTIC_CHECKS`
1 parent 8ed72e7 commit 265fa03

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ on Clang. It was initially intended to be used on
2828
[significant coverage](https://jvoisin.github.io/fortify-headers/)
2929
- Defining `USE_NATIVE_CHK` will make use of compiler-provided builtin `_chk`
3030
functions, which might be a bit better in term of diagnostics,
31-
but won't necesarily provide the same amount of security checks.
32-
31+
but won't necessarily provide the same amount of security checks.
32+
- Defining `PEDANTIC_CHECKS` will enable pedantic checks, that while technically
33+
correct, might break some programs relying on widely accepted
34+
undefined-behaviours.
3335

3436
# Sample usage
3537

include/string.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ __error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the
5151
#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK
5252
return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0));
5353
#else
54+
#if defined PEDANTIC_CHECKS
5455
if (!__od || !__os)
5556
__builtin_trap();
57+
#endif
5658

5759
__fh_size_t __bd = __fh_bos(__od, 0);
5860
__fh_size_t __bs = __fh_bos(__os, 0);
@@ -78,8 +80,10 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
7880
#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK
7981
return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0));
8082
#else
83+
#if defined PEDANTIC_CHECKS
8184
if (!__d || !__s)
8285
__builtin_trap();
86+
#endif
8387

8488
__fh_size_t __bd = __fh_bos(__d, 0);
8589
__fh_size_t __bs = __fh_bos(__s, 0);
@@ -100,8 +104,10 @@ __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert
100104
#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK
101105
return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0));
102106
#else
107+
#if defined PEDANTIC_CHECKS
103108
if (!__d)
104109
__builtin_trap();
110+
#endif
105111

106112
__fh_size_t __b = __fh_bos(__d, 0);
107113

@@ -120,13 +126,14 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t
120126
#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK
121127
return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0));
122128
#else
129+
#if defined PEDANTIC_CHECKS
123130
if (!__d)
124131
__builtin_trap();
125-
126132
#if __STDC_VERSION__ < 201112L
127133
__fh_size_t __b = __fh_bos(__d, 0);
128134
if (__n > __b)
129135
__builtin_trap();
136+
#endif
130137
#endif
131138

132139
return __builtin_memchr(__d, __c, __n);

tests/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CFLAGS+=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2
1+
CFLAGS+=-I../include/ -D_FORTIFY_SOURCE=3 -static -O2 -DPEDANTIC_CHECKS
22

33
COMPTIME_TARGETS= \
44
test_memcpy_overwrite_under \

0 commit comments

Comments
 (0)