Core: Avoid memcpy from NULL

Ben Kallus benjamin.p.kallus.gr at dartmouth.edu
Sat Dec 16 21:26:37 UTC 2023


> In general macro definitions in nginx are used everywhere for
> efficiency reasons

Clang inlines short functions with -O1, and GCC does so with -O2 or
-O1 -finline-small-functions. Are there any platforms that Nginx needs
to support for which short function inlining isn't sufficient to solve
this issue?

> While some might prefer other approaches, writing code like
> "ngx_memcpy(dst, src, ++len)" in nginx is just wrong, and
> shouldn't be trusted to work, much like it won't work with
> "ngx_cpymem(dst, src, ++len)".

It is indeed wrong to use an expression with a side-effect in an
argument to cpymem, but it's also not very obvious that it's wrong. An
inlined function solves the argument reevaluation issue without
performance overhead.

-Ben


More information about the nginx-devel mailing list