* #27201: don't pass out of bounds pointer to memmove

While it might be safe to call memmove(out_of_bounds_dest, y, 0),
we can't assume that memmove won't dereference it's first parameter
even if the last argument is 0.
This commit is contained in:
Tristan Matthews
2013-07-11 18:02:01 -04:00
parent 38cc468293
commit 4a33c93ed8

View File

@ -237,8 +237,10 @@ static void history_calc_maxbuf(jitterbuf *jb)
for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
/* found where it fits */
if (toins > jb->hist_maxbuf[j]) {
/* move over */
memmove(jb->hist_maxbuf + j + 1, jb->hist_maxbuf + j, (JB_HISTORY_MAXBUF_SZ - (j + 1)) * sizeof(jb->hist_maxbuf[0]));
/* move over if there's space */
const size_t slide = (JB_HISTORY_MAXBUF_SZ - (j + 1)) * sizeof(jb->hist_maxbuf[0]);
if (slide > 0)
memmove(jb->hist_maxbuf + j + 1, jb->hist_maxbuf + j, slide);
/* insert */
jb->hist_maxbuf[j] = toins;