hwpfilter/source/hiodev.cxx |   24 +++++++++++-------------
 hwpfilter/source/hiodev.h   |    6 +++---
 2 files changed, 14 insertions(+), 16 deletions(-)

New commits:
commit 12eb35fb90876df0392bf86c19521623ab574766
Author: Caolán McNamara <caol...@redhat.com>
Date:   Fri Jan 26 11:51:43 2018 +0000

    ofz#5717 check state in readblock
    
    and change state to a bool and reuse it more
    
    Change-Id: Iaa46004b144836431dd386a68a8ab688fd1477f2
    Reviewed-on: https://gerrit.libreoffice.org/48686
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/hwpfilter/source/hiodev.cxx b/hwpfilter/source/hiodev.cxx
index bed8b37ce783..fcdc98b24109 100644
--- a/hwpfilter/source/hiodev.cxx
+++ b/hwpfilter/source/hiodev.cxx
@@ -124,13 +124,11 @@ void HStreamIODev::flush()
         gz_flush(_gzfp, Z_FINISH);
 }
 
-
-int HStreamIODev::state() const
+bool HStreamIODev::state() const
 {
-    return 0;
+    return false;
 }
 
-
 /* zlib 관련 부분 */
 bool HStreamIODev::setCompressed(bool flag)
 {
@@ -270,16 +268,14 @@ void HMemIODev::flush()
 {
 }
 
-
-int HMemIODev::state() const
+bool HMemIODev::state() const
 {
     if (pos <= length)
-        return 0;
+        return false;
     else
-        return -1;
+        return true;
 }
 
-
 bool HMemIODev::setCompressed(bool )
 {
     return false;
@@ -288,7 +284,7 @@ bool HMemIODev::setCompressed(bool )
 bool HMemIODev::read1b(unsigned char &out)
 {
     ++pos;
-    if (pos <= length)
+    if (!state())
     {
         out = ptr[pos - 1];
         return true;
@@ -308,7 +304,7 @@ bool HMemIODev::read1b(char &out)
 bool HMemIODev::read2b(unsigned short &out)
 {
     pos += 2;
-    if (pos <= length)
+    if (!state())
     {
          out = ptr[pos - 1] << 8 | ptr[pos - 2];
          return true;
@@ -319,7 +315,7 @@ bool HMemIODev::read2b(unsigned short &out)
 bool HMemIODev::read4b(unsigned int &out)
 {
     pos += 4;
-    if (pos <= length)
+    if (!state())
     {
         out = static_cast<unsigned int>(ptr[pos - 1] << 24 | ptr[pos - 2] << 
16 |
                     ptr[pos - 3] << 8 | ptr[pos - 4]);
@@ -339,6 +335,8 @@ bool HMemIODev::read4b(int &out)
 
 size_t HMemIODev::readBlock(void *p, size_t size)
 {
+    if (state())
+        return 0;
     if (length < pos + size)
         size = length - pos;
     memcpy(p, ptr + pos, size);
@@ -348,7 +346,7 @@ size_t HMemIODev::readBlock(void *p, size_t size)
 
 size_t HMemIODev::skipBlock(size_t size)
 {
-    if (length < pos + size)
+    if (state() || length < pos + size)
         return 0;
     pos += size;
     return size;
diff --git a/hwpfilter/source/hiodev.h b/hwpfilter/source/hiodev.h
index 3e307153fdc5..5f12454da99e 100644
--- a/hwpfilter/source/hiodev.h
+++ b/hwpfilter/source/hiodev.h
@@ -47,7 +47,7 @@ class DLLEXPORT HIODev
 
         virtual bool open() = 0;
         virtual void flush() = 0;
-        virtual int  state() const = 0;
+        virtual bool state() const = 0;
 /* gzip routine wrapper */
         virtual bool setCompressed( bool ) = 0;
 
@@ -91,7 +91,7 @@ class HStreamIODev final: public HIODev
 /**
  * Not implemented.
  */
-        virtual int  state() const override;
+        virtual bool state() const override;
 /**
  * Set whether the stream is compressed or not
  */
@@ -142,7 +142,7 @@ class HMemIODev final: public HIODev
 
         virtual bool open() override;
         virtual void flush() override;
-        virtual int  state() const override;
+        virtual bool state() const override;
 /* gzip routine wrapper */
         virtual bool setCompressed( bool ) override;
         virtual bool read1b(unsigned char &out) override;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to