From 6e977b4f3e4a5aeb1ac024e254caec71ec4baf3f Mon Sep 17 00:00:00 2001 From: ph10 Date: Wed, 12 Apr 2017 13:48:11 +0000 Subject: Fix valgrind warnings for unset padding at the end of the pcre2_real_code structure. git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@743 6239d852-aaf2-0410-a92c-79f79f948069 --- src/pcre2_compile.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index e823747..0c46b52 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -9283,7 +9283,14 @@ if (re == NULL) errorcode = ERR21; goto HAD_CB_ERROR; } + +/* The compiler may put padding at the end of the pcre2_real_code structure in +order to round it up to a multiple of 4 or 8 bytes. This means that when a +compiled pattern is copied (for example, when serialized) undefined bytes are +read, and this annoys debuggers such as valgrind. To avoid this, we explicitly +write to the last 8 bytes of the structure before setting the fields. */ +memset((char *)re + sizeof(pcre2_real_code) - 8, 0, 8); re->memctl = ccontext->memctl; re->tables = tables; re->executable_jit = NULL; -- cgit v1.2.1