-
Stephan Bergmann yazdı
...to avoid potential overflow in psp::appendStr as reported by GCC with --enable-optimized: > vcl/unx/generic/print/psputil.cxx: In function ‘sal_Int32 psp::appendStr(const sal_Char*, sal_Char*)’: > vcl/unx/generic/print/psputil.cxx:127:13: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] > strncpy (pDst, pSrc, nBytes + 1); > ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ > vcl/unx/generic/print/psputil.cxx:126:31: note: length computed here > sal_Int32 nBytes = strlen (pSrc); > ~~~~~~~^~~~~~ Most of the time the original code wrote at the "end" of its char array, so replacements with functionality based on OStringBuffer::append was straightforward. A few places needed to use OStringBuffer::insert to mimic the original code's writing at somewhat random positions in the char array. The functions now taking an OStringBuffer argument still return the amount of characters written. Even if that information would (indirectly) also be available as part of the OStringBuffer's state, keeping the (somewhat redundant now) counting of positions in the calling code should help avoid regressions. Some of the code may be simplified in follow-up commits, dropping the external counting. The original psp::getValueOfDouble is still used elsewhere, so leave it alone for now and add an OStringBuffer overload. Change-Id: I2bb5d51505ca70cba485e6843183496ea3a4ce18 Reviewed-on: https://gerrit.libreoffice.org/66564 Tested-by: Jenkins Reviewed-by:
Stephan Bergmann <sbergman@redhat.com>
49d8cc18