Make STORE_ARRAY8 and STORE_LISTOF_PROPERTY fill holes in the buffer with zero bytes rather than leaving whatever was in that memory the previous cycle through the scratch buffer. (Prior to the scratch buffer being zero-filled when allocated, which was done to fix https://bugs.freedesktop.org/show_bug.cgi?id=17644 , this problem led to valgrind warnings. I believe this fix is a better way to fix those warnings.)
Fixes https://bugs.freedesktop.org/show_bug.cgi?id=25785 (I admit to editing the STORE_ARRAY8 changes to merge with upstream since I last tested the patch.) --- src/SMlibint.h | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/SMlibint.h b/src/SMlibint.h index a478b48..e3ac3e4 100644 --- a/src/SMlibint.h +++ b/src/SMlibint.h @@ -201,25 +201,34 @@ in this Software without prior written authorization from The Open Group. * STORE FOO */ +#define STORE_ZERO_PADDING(_pBuf, _len) \ +{ \ + memset (_pBuf, 0, _len); \ + _pBuf += _len; \ +} + #define STORE_ARRAY8(_pBuf, _len, _array8) \ { \ STORE_CARD32 (_pBuf, _len); \ - if (_len) \ + if (_len) { \ memcpy (_pBuf, _array8, _len); \ - _pBuf += _len + PAD64 (4 + _len); \ + _pBuf += _len; \ + } \ + if (PAD64 (4 + _len)) \ + STORE_ZERO_PADDING (_pBuf, PAD64 (4 + _len)); \ } #define STORE_LISTOF_PROPERTY(_pBuf, _count, _props) \ { \ int _i, _j; \ STORE_CARD32 (_pBuf, _count); \ - _pBuf += 4; \ + STORE_ZERO_PADDING (_pBuf, 4); \ for (_i = 0; _i < _count; _i++) \ { \ STORE_ARRAY8 (_pBuf, strlen (_props[_i]->name), _props[_i]->name); \ STORE_ARRAY8 (_pBuf, strlen (_props[_i]->type), _props[_i]->type); \ STORE_CARD32 (_pBuf, _props[_i]->num_vals); \ - _pBuf += 4; \ + STORE_ZERO_PADDING (_pBuf, 4); \ for (_j = 0; _j < _props[_i]->num_vals; _j++) \ { \ STORE_ARRAY8 (_pBuf, _props[_i]->vals[_j].length, \ -- 1.7.4.1 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
