jvoisin / fortify-headers

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

Avoid unnecessarily calling slower functions #17

Open N-R-K opened 1 year ago

N-R-K commented 1 year ago

For example, in strcpy (ignoring the UB overlapping check):

https://github.com/jvoisin/fortify-headers/blob/9aa4490263ead62dc545cf0e8b83e0ef77eb7a6e/include/string.h#L139-L150

By the time, __orig_strcpy is called, the length has already been computed and has been established to be in bound. There's no need to pay for the nul-byte search again inside of __orig_strcpy when the faster memcpy can be called instead.

Some of the other str* functions suffer from the same issue.

jvoisin commented 1 year ago

The rationale behind this was that maybe other things were "hooking" strcpy, but you're right, a call to memcpy makes sense.