fix bugs when buffer is empty.
[apps/madmutt.git] / lib-lib / buffer.h
index 9e919b7..dd9d936 100644 (file)
@@ -87,8 +87,10 @@ static inline void buffer_addch(buffer_t *buf, int c) {
 }
 
 static inline void buffer_reset(buffer_t *buf) {
-    buf->len = 0;
-    buf->data[0] = '\0';
+    if (buf->len) {
+        buf->len = 0;
+        buf->data[0] = '\0';
+    }
 }