summaryrefslogtreecommitdiff
path: root/lib/Buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Buffer.cc')
-rw-r--r--lib/Buffer.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
index b3cb10b..afbaa6f 100644
--- a/lib/Buffer.cc
+++ b/lib/Buffer.cc
@@ -10,6 +10,9 @@ Buffer::~Buffer() {
}
ssize_t Buffer::write(const void *buf, size_t count) {
+ if (!count) {
+ return 0;
+ }
if (count + realsiz > bufsiz) {
int numblocks = (count + realsiz) / realloc_threshold;
int remains = (count + realsiz) % realloc_threshold;
@@ -33,10 +36,10 @@ ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) {
if (ptr >= realloc_threshold) {
int numblocks = (bufsiz / realloc_threshold) - (ptr / realloc_threshold);
- memmove(buffer, buffer + numblocks * realloc_threshold, numblocks * realloc_threshold);
+ memmove(buffer, buffer + (bufsiz - numblocks * realloc_threshold), numblocks * realloc_threshold);
+ ptr -= (bufsiz - numblocks * realloc_threshold);
+ realsiz -= (bufsiz - numblocks * realloc_threshold);
buffer = (char *) realloc(buffer, bufsiz = (numblocks * realloc_threshold));
- ptr -= numblocks * realloc_threshold;
- realsiz -= numblocks * realloc_threshold;
}
return count;