assert non-NULL ptrs before calling mem funcs

The definitions of memcpy(), memmove(), and memset() state that
the behaviour is undefined if any of the pointer arguments are
NULL, and some compilers are known to make use of this to
optimise away existing NULL checks in the source.

Change-Id: I489bc256e3eac7ff41d91becb0b43aba73dbb3f9
Link: https://www.imperialviolet.org/2016/06/26/nonnull.html
This commit is contained in:
Jeffrey Altman
2022-01-19 22:55:33 -05:00
committed by Jeffrey Altman
parent d35c9b2d67
commit 190263bb7a
6 changed files with 171 additions and 47 deletions

View File

@@ -167,10 +167,13 @@ arcfour_mic_cksum_iov(krb5_context context,
continue;
}
memcpy(ptr + ofs,
iov[i].buffer.value,
iov[i].buffer.length);
ofs += iov[i].buffer.length;
if (iov[i].buffer.length > 0) {
assert(iov[i].buffer.value != NULL);
memcpy(ptr + ofs,
iov[i].buffer.value,
iov[i].buffer.length);
ofs += iov[i].buffer.length;
}
}
if (padding) {