From bfe22a77a653de7940fafa534ba035c41329c29e Mon Sep 17 00:00:00 2001 From: "Steffen (Daode) Nurpmeso" Date: Fri, 2 May 2014 16:59:27 +0200 Subject: [PATCH] struct eval_ctx: add .ev_line_size; commands(): fix `ghost'.. I got some alert() messages from the string dope after `ghost' expansion and it turned out that commands() calls evaluate() with ev_line being set to the full buffer size, rather than the real line size, leading to faulty much-too-large allocations for the ghost expansion buffer; didn't cause problems because the terminating zero would be part of the too-large-a-copy, but oops. So introduce another storage for the buffer allocation size and use it as a switch buffer with set.ev_line.l before callings evaluate(). --- lex.c | 3 +++ nail.h | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lex.c b/lex.c index 2e68f4bb..47b02a06 100644 --- a/lex.c +++ b/lex.c @@ -741,8 +741,11 @@ commands(void) /* Read a line of commands and handle end of file specially */ jreadline: + ev.ev_line.l = ev.ev_line_size; n = readline_input(NULL, TRU1, &ev.ev_line.s, &ev.ev_line.l, ev.ev_new_content); + ev.ev_line_size = (ui32_t)ev.ev_line.l; + ev.ev_line.l = (ui32_t)n; _reset_on_stop = 0; if (n < 0) { /* EOF */ diff --git a/nail.h b/nail.h index b3c397b1..f284e936 100644 --- a/nail.h +++ b/nail.h @@ -975,9 +975,10 @@ struct search_expr { }; struct eval_ctx { - struct str ev_line; + struct str ev_line; /* The terminated data to evaluate */ + ui32_t ev_line_size; /* May be used to store line memory size */ bool_t ev_is_recursive; /* Evaluation in evaluation? (collect ~:) */ - ui8_t __dummy[6]; + ui8_t __dummy[3]; bool_t ev_add_history; /* Enter (final) command in history? */ char const *ev_new_content; /* History: reenter line, start with this */ }; -- 2.11.4.GIT