From d9fb9e0065b85ee47710bbcba7a81a5266e9e948 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 17 May 2007 00:04:06 +0200 Subject: [PATCH] fix bugs when buffer is empty. --- lib-lib/buffer.h | 6 ++++-- lib-sys/mutt_socket.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) 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; -- 2.20.1