diff options
author | David Tardon <dtardon@redhat.com> | 2014-02-27 13:49:25 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2014-02-27 23:40:28 +0100 |
commit | 95b401558466954453d490456be01beb6d747806 (patch) | |
tree | a43fed42129a1e6f20193920d940627484fa20a0 /tools/source/stream | |
parent | 89ca2fd794413e91c1ead4d87abe76c23d37d481 (diff) |
do not crash if allocation failed
Change-Id: I2fbc259de52a3c7f2c8c33027d74bb857d44b437
Diffstat (limited to 'tools/source/stream')
-rw-r--r-- | tools/source/stream/stream.cxx | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx index 476f1a86f1dd..1c8ac210e914 100644 --- a/tools/source/stream/stream.cxx +++ b/tools/source/stream/stream.cxx @@ -2056,14 +2056,18 @@ OString read_uInt8s_ToOString(SvStream& rStrm, sal_Size nLen) //alloc a (ref-count 1) rtl_String of the desired length. //rtl_String's buffer is uninitialized, except for null termination pStr = rtl_string_alloc(sal::static_int_cast<sal_Int32>(nLen)); - sal_Size nWasRead = rStrm.Read(pStr->buffer, nLen); - if (nWasRead != nLen) + SAL_WARN_IF(!pStr, "tools", "allocation failed"); + if (pStr) { - //on (typically unlikely) short read set length to what we could - //read, and null terminate. Excess buffer capacity remains of - //course, could create a (true) replacement OString if it matters. - pStr->length = sal::static_int_cast<sal_Int32>(nWasRead); - pStr->buffer[pStr->length] = 0; + sal_Size nWasRead = rStrm.Read(pStr->buffer, nLen); + if (nWasRead != nLen) + { + //on (typically unlikely) short read set length to what we could + //read, and null terminate. Excess buffer capacity remains of + //course, could create a (true) replacement OString if it matters. + pStr->length = sal::static_int_cast<sal_Int32>(nWasRead); + pStr->buffer[pStr->length] = 0; + } } } @@ -2081,19 +2085,23 @@ OUString read_uInt16s_ToOUString(SvStream& rStrm, sal_Size nLen) //alloc a (ref-count 1) rtl_uString of the desired length. //rtl_String's buffer is uninitialized, except for null termination pStr = rtl_uString_alloc(sal::static_int_cast<sal_Int32>(nLen)); - sal_Size nWasRead = rStrm.Read(pStr->buffer, nLen*2)/2; - if (nWasRead != nLen) - { - //on (typically unlikely) short read set length to what we could - //read, and null terminate. Excess buffer capacity remains of - //course, could create a (true) replacement OUString if it matters. - pStr->length = sal::static_int_cast<sal_Int32>(nWasRead); - pStr->buffer[pStr->length] = 0; - } - if (rStrm.IsEndianSwap()) + SAL_WARN_IF(!pStr, "tools", "allocation failed"); + if (pStr) { - for (sal_Int32 i = 0; i < pStr->length; ++i) - pStr->buffer[i] = OSL_SWAPWORD(pStr->buffer[i]); + sal_Size nWasRead = rStrm.Read(pStr->buffer, nLen*2)/2; + if (nWasRead != nLen) + { + //on (typically unlikely) short read set length to what we could + //read, and null terminate. Excess buffer capacity remains of + //course, could create a (true) replacement OUString if it matters. + pStr->length = sal::static_int_cast<sal_Int32>(nWasRead); + pStr->buffer[pStr->length] = 0; + } + if (rStrm.IsEndianSwap()) + { + for (sal_Int32 i = 0; i < pStr->length; ++i) + pStr->buffer[i] = OSL_SWAPWORD(pStr->buffer[i]); + } } } |