From e548c9475051d488061a7c4e4e68bb066b2520f2 Mon Sep 17 00:00:00 2001 From: Dan Cross Date: Thu, 11 Oct 2018 12:55:00 +0000 Subject: [PATCH] mail_menu.c: Remove external `lines` counter in `editor`. The pointer vector maintaining `content` in `editor` already keeps track of the number of lines and makes it available via a call to `ptr_vector_len` (or one could look at th `len` member of the ptr_vector struct...this is C, not some fancy object oriented language with data hiding). Delete the `lines` local variable and just use ptr_vector_len where necessary. Sorry; I should have done that in the first sweep through that code. My bad! Signed-off-by: Dan Cross --- src/mail_menu.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/mail_menu.c b/src/mail_menu.c index 1790509..370990e 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -546,7 +546,6 @@ char *external_editor(struct user_record *user, char *to, char *from, char *quot } char *editor(struct user_record *user, char *quote, int quotelen, char *from, int email, int sig) { - int lines = 0; char buffer[256]; char linebuffer[80]; int doquit = 0; @@ -593,7 +592,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in s_printf(get_string(87)); while (!doquit) { - s_printf(get_string(88), lines, ""); + s_printf(get_string(88), ptr_vector_len(&content), ""); strlcpy(linebuffer, next_line_buffer, sizeof(linebuffer)); s_readstring_inject(linebuffer, 70, next_line_buffer); memset(next_line_buffer, 0, 70); @@ -712,7 +711,6 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in for (i = qfrom; i <= qto; i++) { char *copy = strdup(ptr_vector_get("econtent, i)); ptr_vector_append(&content, copy); - lines++; } s_printf(get_string(86)); @@ -745,7 +743,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in s_printf(get_string(39)); } else { z = atoi(buffer); - if (z < 0 || z >= lines) { + if (z < 0 || z >= ptr_vector_len(&content)) { s_printf(get_string(39)); } else { free(ptr_vector_del(&content, i)); @@ -758,7 +756,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in s_printf(get_string(39)); } else { z = atoi(buffer); - if (z < 0 || z >= lines) { + if (z < 0 || z >= ptr_vector_len(&content)) { s_printf(get_string(39)); } else { s_printf(get_string(88), z, ptr_vector_get(&content, z)); @@ -775,7 +773,7 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in s_printf(get_string(39)); } else { z = atoi(buffer); - if (z < 0 || z >= lines) { + if (z < 0 || z >= ptr_vector_len(&content)) { s_printf(get_string(39)); } else { s_printf(get_string(103), z); @@ -786,7 +784,6 @@ char *editor(struct user_record *user, char *quote, int quotelen, char *from, in } } else { ptr_vector_append(&content, strdup(linebuffer)); - lines++; } } if (quote != NULL) {