Skip to content

Commit

Permalink
Avoid an undefined behavior of memcpy() in _tr_stored_block().
Browse files Browse the repository at this point in the history
Allegedly the behavior of memcpy() is undefined if the source
pointer is NULL, even if the number of bytes to copy is zero.
  • Loading branch information
madler committed Oct 13, 2017
1 parent b25d5fc commit 723e928
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
bi_windup(s); /* align on byte boundary */
put_short(s, (ush)stored_len);
put_short(s, (ush)~stored_len);
zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
if (stored_len)
zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
s->pending += stored_len;
#ifdef ZLIB_DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
Expand Down

0 comments on commit 723e928

Please sign in to comment.