diff --git a/src/StreamBuffer.cc b/src/StreamBuffer.cc index 77bf747..fa970e5 100644 --- a/src/StreamBuffer.cc +++ b/src/StreamBuffer.cc @@ -273,9 +273,18 @@ StreamBuffer StreamBuffer::expand(long start, long length) const if (start < 0) { start += len; - if (start < 0) start = 0; } - end = length >= 0 ? start+length : len; + if (length < 0) + { + start += length; + length = -length; + } + if (start < 0) + { + length += start; + start = 0; + } + end = start+length; if (end > len) end = len; StreamBuffer result((end-start)*2); start += offs; diff --git a/src/StreamBuffer.h b/src/StreamBuffer.h index 563830b..9bf8585 100644 --- a/src/StreamBuffer.h +++ b/src/StreamBuffer.h @@ -218,7 +218,10 @@ public: // expand: create copy of StreamBuffer where all nonprintable characters // are replaced by with xx being the hex code of the characters - StreamBuffer expand(long start=0, long length=-1) const; + StreamBuffer expand(long start, long length) const; + + StreamBuffer expand(long start=0) const + {return expand(start, len);} // dump: debug function, like expand but also show the 'hidden' memory // before and after the real data. Uses colours.