From: Pierre Habouzit Date: Wed, 16 May 2007 22:04:06 +0000 (+0200) Subject: fix bugs when buffer is empty. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=d9fb9e0065b85ee47710bbcba7a81a5266e9e948 fix bugs when buffer is empty. --- diff --git a/lib-lib/buffer.h b/lib-lib/buffer.h index 9e919b7..dd9d936 100644 --- a/lib-lib/buffer.h +++ b/lib-lib/buffer.h @@ -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'; + } } diff --git a/lib-sys/mutt_socket.c b/lib-sys/mutt_socket.c index 194ad5a..af88be0 100644 --- a/lib-sys/mutt_socket.c +++ b/lib-sys/mutt_socket.c @@ -156,7 +156,7 @@ int mutt_socket_readln2(buffer_t *buf, CONNECTION *conn) 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;