HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pagesend -- Bug in StackBuffer



Hi Philippe,

I looked at you patch, i think there might be a better way of doing it.

The cause of the problem is that in ths fxStackBuffer class there is no
equals operator ( ie operator= ) function defined.  The C++ compiler
therefore drops back to doing a memberwise copy which is fine if copying
regular numbers but breaks badly for pointers and dynamically allocated data.

A defined operator= would catch other instances of code assigning one
fxStackBuffer to another.

I have included a patch below that does this - warning it needs testing!!!

PS If you need a Stack today in new C++ code don't write your own, use the
STL :-)

- Robert

*** StackBuffer.h.orig  Sat Feb 14 21:47:49 1998
--- StackBuffer.h       Mon Jul 27 11:04:21 1998
***************
*** 60,65 ****
--- 60,66 ----
      operator const unsigned char*() const;// Return base of buffer
      char& operator[](u_int i) const;  // Return character in buffer
      char& operator[](int i) const;    // Return character in buffer
+     fxStackBuffer& operator=(const fxStackBuffer&);
  protected:
      char      buf[1000];
      char*     next;     

c StackBuffer.c++.orig StackBuffer.c++
*** StackBuffer.c++.orig        Sat Feb 14 21:47:26 1998
--- StackBuffer.c++     Mon Jul 27 11:41:36 1998
***************
*** 117,119 ****
--- 117,133 ----
      vput(fmt, ap);
      va_end(ap);
  }
+
+ fxStackBuffer& fxStackBuffer::operator=(const fxStackBuffer& other)
+ {
+     if (&other != this) {
+         u_int size = other.end - other.base;
+         u_int len = other.getLength();
+         if (base != buf) free(base);
+         base = (size > sizeof(buf)) ? (char*) malloc(size) : &buf[0];
+         end = base + size;
+         next = base + len;
+         memcpy(base, other.base, len);
+    }
+    return *this;
+ }           

 




Project hosted by iFAX Solutions