jvoisin / fortify-headers

Standalone portable header-based implementation of FORTIFY_SOURCE=3
BSD Zero Clause License
19 stars 3 forks source link

Add compile-time checks #26

Open jvoisin opened 1 year ago

jvoisin commented 1 year ago

Something like:

void *memcpy(void  *d, const void *s, size_t __n) {
  if (__builtin_constant_p(__n) && __n > __bos(od)) {
    compile-time-error!
  }
}

Apparently, the trick everyone is using to make the compiler choke is this one:

#define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg)))
#define __warnattr(msg) __attribute__((__warning__(msg)))

This should be used only when warning_if isn't supported.