An upcoming change makes it possible to enter this function with `xb->ptr` as
`NULL`. It looks as if there is nothing wrong with this; a zero-sized string
fits in any agxbuf, including an unallocated one. However UBSan educates us that
calling `memcpy` with a `NULL` destination pointer is undefined behavior, even
when the passed size is 0. So this change avoids reaching `memcpy` when we know
the function will be a no-op.
Note that this is sort of fixing a latent bug, in that an agxbuf user could
already cause the scenario described above by `agxbdisown`ing an agxbuf and then
calling `agxbput_n` on it with size 0. However no existing callers do this.
* Append string s of length ssz into xb
*/
static inline size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz) {
+ if (ssz == 0) {
+ return 0;
+ }
if (xb->ptr + ssz > xb->eptr)
agxbmore(xb, ssz);
memcpy(xb->ptr, s, ssz);