From 0dfd493417aa1e39f7fad83875da4e577e921fee Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 4 Oct 2019 01:50:00 +0100 Subject: [PATCH] fix max quote depth --- color.c | 18 ++++++++---------- color.h | 2 -- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/color.c b/color.c index 04a704a5b..763d5fc00 100644 --- a/color.c +++ b/color.c @@ -63,10 +63,12 @@ typedef int (*parser_callback_t)(struct Buffer *buf, struct Buffer *s, uint32_t *fg, uint32_t *bg, int *attr, struct Buffer *err); +#define COLOR_UNSET UINT32_MAX +#define COLOR_QUOTES_MAX 9 + #ifdef HAVE_COLOR #define COLOR_DEFAULT (-2) -#define COLOR_UNSET UINT32_MAX /* * Flags for the high 8bits of the color value. @@ -150,8 +152,6 @@ static const struct Mapping ComposeFields[] = { }; // clang-format off -#define COLOR_QUOTE_INIT 8 - /** * color_line_new - Create a new ColorLine * @retval ptr Newly allocated ColorLine @@ -211,9 +211,8 @@ void mutt_color_init(void) Colors = mutt_mem_calloc(1, sizeof(*Colors)); Colors->defs = mutt_mem_malloc(MT_COLOR_MAX * sizeof(int)); memset(Colors->defs, A_NORMAL, sizeof(int) * MT_COLOR_MAX); - Colors->quotes = mutt_mem_malloc(COLOR_QUOTE_INIT * sizeof(int)); - memset(Colors->quotes, A_NORMAL, sizeof(int) * COLOR_QUOTE_INIT); - Colors->quotes_size = COLOR_QUOTE_INIT; + Colors->quotes = mutt_mem_malloc(COLOR_QUOTES_MAX * sizeof(int)); + memset(Colors->quotes, A_NORMAL, COLOR_QUOTES_MAX * sizeof(int)); Colors->quotes_used = 0; /* set some defaults */ @@ -1140,11 +1139,10 @@ static enum CommandResult parse_color(struct Buffer *buf, struct Buffer *s, } else if (object == MT_COLOR_QUOTED) { - if (q_level >= Colors->quotes_size) + if (q_level >= COLOR_QUOTES_MAX) { - mutt_mem_realloc(&Colors->quotes, (Colors->quotes_size += 2) * sizeof(int)); - Colors->quotes[Colors->quotes_size - 2] = Colors->defs[MT_COLOR_QUOTED]; - Colors->quotes[Colors->quotes_size - 1] = Colors->defs[MT_COLOR_QUOTED]; + mutt_buffer_printf(err, _("Maximum quoting level is %d"), COLOR_QUOTES_MAX-1); + return MUTT_CMD_WARNING; } if (q_level >= Colors->quotes_used) Colors->quotes_used = q_level + 1; diff --git a/color.h b/color.h index 7c5fb3fd1..610161724 100644 --- a/color.h +++ b/color.h @@ -142,8 +142,6 @@ struct Colors int *quotes; ///< Array of colours for quoted email text int quotes_used; ///< Number of colours for quoted email text - int quotes_size; - struct ColorList *user_colors; int num_user_colors; -- 2.40.0