[Libreoffice-commits] core.git: Branch 'libreoffice-5-3' - hwpfilter/source
Caolán McNamara
caolanm at redhat.com
Mon Mar 6 14:39:12 UTC 2017
hwpfilter/source/hstream.cxx | 21 ++++++++++-----------
hwpfilter/source/hstream.hxx | 11 +++++------
2 files changed, 15 insertions(+), 17 deletions(-)
New commits:
commit ecad9326a0e40a4bfe1e3c8232ee1a1f5cb84a65
Author: Caolán McNamara <caolanm at redhat.com>
Date: Sat Mar 4 20:58:26 2017 +0000
Resolves: ofz#727 don't allow negative sizes or indexes
remove extra size in favour of vector size and don't resize
and memcpy data, just use vector::insert
Change-Id: I8efb91a8c11fbd862c0458042554cf7e94b813cd
Reviewed-on: https://gerrit.libreoffice.org/34892
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Stahl <mstahl at redhat.com>
diff --git a/hwpfilter/source/hstream.cxx b/hwpfilter/source/hstream.cxx
index 6a0d59f..6b5bf98 100644
--- a/hwpfilter/source/hstream.cxx
+++ b/hwpfilter/source/hstream.cxx
@@ -22,38 +22,37 @@
#include "hstream.hxx"
HStream::HStream()
- : size(0)
- , pos(0)
+ : pos(0)
{
}
-void HStream::addData(const byte *buf, int aToAdd)
+void HStream::addData(const byte *buf, size_t aToAdd)
{
- seq.resize(size + aToAdd);
- memcpy(seq.data() + size, buf, aToAdd);
- size += aToAdd;
+ seq.insert(seq.end(), buf, buf + aToAdd);
}
-int HStream::readBytes(byte * buf, int aToRead)
+size_t HStream::readBytes(byte * buf, size_t aToRead)
{
+ auto size = seq.size();
if (aToRead >= (size - pos))
aToRead = size - pos;
- for (int i = 0; i < aToRead; i++)
+ for (size_t i = 0; i < aToRead; ++i)
buf[i] = seq[pos++];
return aToRead;
}
-int HStream::skipBytes(int aToSkip)
+size_t HStream::skipBytes(size_t aToSkip)
{
+ auto size = seq.size();
if (aToSkip >= (size - pos))
aToSkip = size - pos;
pos += aToSkip;
return aToSkip;
}
-int HStream::available() const
+size_t HStream::available() const
{
- return size - pos;
+ return seq.size() - pos;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/hwpfilter/source/hstream.hxx b/hwpfilter/source/hstream.hxx
index 4374b92..e6654f7 100644
--- a/hwpfilter/source/hstream.hxx
+++ b/hwpfilter/source/hstream.hxx
@@ -34,24 +34,23 @@ class HStream
/**
*
*/
- void addData( const byte *buf, int aToAdd);
+ void addData( const byte *buf, size_t aToAdd);
/**
* Read some byte to buf as given size
*/
- int readBytes( byte *buf, int aToRead);
+ size_t readBytes( byte *buf, size_t aToRead);
/**
* Skip some byte from stream as given size
*/
- int skipBytes( int aToSkip );
+ size_t skipBytes( size_t aToSkip );
/**
* @returns Size of remained stream
*/
- int available() const;
+ size_t available() const;
private:
- int size;
std::vector<byte> seq;
- int pos;
+ size_t pos;
};
#endif
More information about the Libreoffice-commits
mailing list