diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-12-14 23:52:25 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-12-15 12:22:49 +0000 |
commit | cf880b3f1f5e9a08ef6be30791dbf28d2d74cfcf (patch) | |
tree | 8ad578daa7c3c4ea874be7a1a6f9101014b82475 /sc | |
parent | 66c3655a07e109d88183002192410bcc9866c0f2 (diff) |
refactor ScfTools::ReadCString
fix potential bug on short read which has bugged me for a while
where bytes read is always reduced without a check that byte was
read
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/ftools/ftools.cxx | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/sc/source/filter/ftools/ftools.cxx b/sc/source/filter/ftools/ftools.cxx index b346295455e0..a1ca318a0125 100644 --- a/sc/source/filter/ftools/ftools.cxx +++ b/sc/source/filter/ftools/ftools.cxx @@ -278,35 +278,16 @@ ScStyleSheet& ScfTools::MakePageStyleSheet( ScStyleSheetPool& rPool, const Strin ByteString ScfTools::ReadCString( SvStream& rStrm ) { - rtl::OStringBuffer aRet; - - while (1) - { - sal_Char cChar(0); - rStrm >> cChar; - if (!cChar) - break; - aRet.append(cChar); - } - - return aRet.makeStringAndClear(); + return read_zeroTerminated_uInt8s_AsOString(rStrm); } ByteString ScfTools::ReadCString( SvStream& rStrm, sal_Int32& rnBytesLeft ) { - rtl::OStringBuffer aRet; - - while (1) - { - sal_Char cChar(0); - rStrm >> cChar; - rnBytesLeft--; - if (!cChar) - break; - aRet.append(cChar); - } - - return aRet.makeStringAndClear(); + rtl::OString aRet(read_zeroTerminated_uInt8s_AsOString(rStrm)); + rnBytesLeft -= aRet.getLength(); //we read this number of bytes anyway + if (rStrm.good()) //if the stream is happy we read the null terminator as well + --rnBytesLeft; + return aRet; } void ScfTools::AppendCString( SvStream& rStrm, String& rString, rtl_TextEncoding eTextEnc ) |