From: Ulya Trofimovich Date: Fri, 18 Nov 2016 16:29:09 +0000 (+0000) Subject: Skeleton: generate proper keys for tags. X-Git-Tag: 1.0~39^2~224 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2db0433b08bbda2d872eeae26b159a0d5e2daf2a;p=re2c Skeleton: generate proper keys for tags. Instead of calculating all necessary keys, then attributing keys of the first path to all paths, write proper keys for each path. Found by slyfox's fuzzer. :) --- diff --git a/re2c/src/ir/skeleton/generate_data.cc b/re2c/src/ir/skeleton/generate_data.cc index 0b8db187..b14c5f43 100644 --- a/re2c/src/ir/skeleton/generate_data.cc +++ b/re2c/src/ir/skeleton/generate_data.cc @@ -199,16 +199,14 @@ static void write_keys(const path_t &path, const Skeleton &skel, // keys: 1 - scanned length, 2 - matched length, 3 - matched rule, the rest - tags const size_t nkey = 3 + htag - ltag; key_t *keys = new key_t[nkey * width], *k = keys; - // 1st path - *k++ = to_le(static_cast(path.len())); - *k++ = to_le(static_cast(matched)); - *k++ = to_le(rule2key(rule, skel.defrule)); - for (size_t t = ltag; t < htag; ++t) { - *k++ = to_le(static_cast(tags[vers[t]])); - } - // remaining paths: copy-paste keys from 1st path - for (size_t w = 1; w < width; ++w, k += nkey) { - memcpy(k, keys, nkey * sizeof(key_t)); + for (size_t w = 0; w < width; ++w) { + *k++ = to_le(static_cast(path.len())); + *k++ = to_le(static_cast(matched)); + *k++ = to_le(rule2key(rule, skel.defrule)); + const size_t *ts = &tags[w * nver]; + for (size_t t = ltag; t < htag; ++t) { + *k++ = to_le(static_cast(ts[vers[t]])); + } } // dump to file fwrite(keys, sizeof(key_t), nkey * width, file);