fix bugs when buffer is empty.
authorPierre Habouzit <madcoder@debian.org>
Wed, 16 May 2007 22:04:06 +0000 (00:04 +0200)
committerPierre Habouzit <madcoder@debian.org>
Wed, 16 May 2007 22:04:06 +0000 (00:04 +0200)
lib-lib/buffer.h
lib-sys/mutt_socket.c

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) {
 }
 
 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';
+    }
 }
 
 
 }
 
 
index 194ad5a..af88be0 100644 (file)
@@ -156,7 +156,7 @@ int mutt_socket_readln2(buffer_t *buf, CONNECTION *conn)
 
     while (mutt_socket_readchar(conn, &ch) == 1) {
         if (ch == '\n') {
 
     while (mutt_socket_readchar(conn, &ch) == 1) {
         if (ch == '\n') {
-            if (buf->data[buf->len - 1] == '\r') {
+            if (buf->len && buf->data[buf->len - 1] == '\r') {
                 buf->data[--buf->len] = '\0';
             }
             return 0;
                 buf->data[--buf->len] = '\0';
             }
             return 0;