From 2e24a66b883b7f14d9dd0aeffa749d68dd5d6939 Mon Sep 17 00:00:00 2001 From: mame Date: Mon, 18 Dec 2017 02:44:36 +0000 Subject: iseq.c (finish_iseq_build): fix coverage leakage [Bug #14191] Before this change, coverage.so had failed to measure some multiple-line code fragments. This is because removing trace instructions (#14104) changed TracePoint's lineno (new lineno), and coverage counter array was based on old lineno. This change initializes coverage counter array based on new lineno. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61313 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- iseq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'iseq.c') diff --git a/iseq.c b/iseq.c index 186f8622e7..f0239ccde1 100644 --- a/iseq.c +++ b/iseq.c @@ -350,9 +350,21 @@ finish_iseq_build(rb_iseq_t *iseq) { struct iseq_compile_data *data = ISEQ_COMPILE_DATA(iseq); VALUE err = data->err_info; + unsigned int i; ISEQ_COMPILE_DATA_CLEAR(iseq); compile_data_free(data); + if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) { + for (i = 0; i < iseq->body->insns_info_size; i++) { + if (iseq->body->insns_info[i].events & RUBY_EVENT_LINE) { + int line_no = iseq->body->insns_info[i].line_no - 1; + if (0 <= line_no && line_no < RARRAY_LEN(ISEQ_LINE_COVERAGE(iseq))) { + RARRAY_ASET(ISEQ_LINE_COVERAGE(iseq), line_no, INT2FIX(0)); + } + } + } + } + if (RTEST(err)) { VALUE path = pathobj_path(iseq->body->location.pathobj); if (err == Qtrue) err = rb_exc_new_cstr(rb_eSyntaxError, "compile error"); -- cgit v1.2.3