From 237722c0b2065f3abf32f479fffaf59105dff150 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Tue, 27 Oct 2020 19:40:30 -0400 Subject: [PATCH] fix crash when cleaning up functions related to [[accumulate]] --- Makefile | 2 +- parser.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dc49416..06690a7 100644 --- a/Makefile +++ b/Makefile @@ -149,7 +149,7 @@ ifeq ($(UBSAN),1) endif # Strip the binaries when not a debug build -ifneq (,$(findstring, -g,$(CXXFLAGS))) +ifneq (,$(findstring -g,$(CXXFLAGS))) STRIP := true else STRIP := strip diff --git a/parser.cpp b/parser.cpp index 9345760..b0afc79 100644 --- a/parser.cpp +++ b/parser.cpp @@ -4178,8 +4178,18 @@ static bool parse_function_body(parser_t *parser, ast_value *var) enderrfn: (void)!parser_leaveblock(parser); - parser->functions.pop_back(); + delete func; + + // Remove |func| from |parser->functions|. It may not actually be at the + // back of the vector for accumulated functions. + for (auto it = parser->functions.begin(); it != parser->functions.end(); it++) { + if (*it == func) { + parser->functions.erase(it, it + 1); + break; + } + } + var->m_constval.vfunc = nullptr; enderr: -- 2.39.2