Skip to content

[base] Avoid UB with memcpy

Ben Wagner requested to merge bungeman/freetype:fix_var_memcpy_src_null into master

FT_NEW_ARRAY(p, 0) sets p to NULL. FT_Stream_ReadAt with a memory based stream uses FT_MEM_COPY which is memcpy which specifies that it is undefined behavior for either the src or dst to be NULL. Instead of forcing all callers work around calling FT_Stream_Read when buffer == NULL && count == 0 do the check in FT_StreamRead. This allows any call with count == 0 to succesfully read zero bytes without UB.

  • src/base/ftstream.c (FT_Stream_ReadAt): skip FT_MEM_COPY when count == 0. (FT_Stream_TryRead): ditto

Fixes: #1250 (closed)

Edited by Ben Wagner

Merge request reports