Skip to content

Avoid unnecessarily calling slower functions #17

Description

@N-R-K

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

size_t __n = strlen(__s) + 1;
/* trap if pointers are overlapping but not if dst == src.
* gcc seems to like to generate code that relies on dst == src */
if ((__d < __s && __d + __n > __s) ||
(__s < __d && __s + __n > __d))
__builtin_trap();
size_t __b = __bos(__d, 0);
if (__n > __b)
__builtin_trap();
return __orig_strcpy(__d, __s);

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions