From 54d18a279a01b4643bad4c98e13f365d7dc2cc75 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 15 Dec 2015 03:35:26 +0000 Subject: [PATCH] Robustify mpers.awk against input containing index loops Make mpers.awk check for potential index loops. Such loops should not normally happen, but mpers.awk will not go into infinite recursion if they do. * mpers.awk (enter, leave): New functions. (what_is): Use them. --- mpers.awk | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mpers.awk b/mpers.awk index f511acff..4c2def2f 100644 --- a/mpers.awk +++ b/mpers.awk @@ -15,9 +15,26 @@ function array_get(array_idx, array_member, array_return) } return array_return } +function enter(array_idx) +{ + if (called[array_idx]) { + printf("%s: index loop detected:", FILENAME) > "/dev/stderr" + for (item in called) + printf(" %s", item) > "/dev/stderr" + print "" > "/dev/stderr" + exit 1 + } + called[array_idx] = 1 +} +function leave(array_idx, to_return) +{ + delete called[array_idx] + return to_return +} function what_is(what_idx, type_idx, special, item, \ location, prev_location, prev_returned_size) { + enter(what_idx) special = array_get(what_idx, "special") switch (special) { case "base_type": @@ -52,7 +69,7 @@ function what_is(what_idx, type_idx, special, item, \ returned_size = to_return * returned_size if ("" == to_return) to_return = "00" - return to_return + return leave(what_idx, to_return) break case "structure_type": print "struct {" @@ -107,18 +124,18 @@ function what_is(what_idx, type_idx, special, item, \ break case "typedef": type_idx = array_get(what_idx, "type") - return what_is(type_idx) + return leave(what_idx, what_is(type_idx)) break case "member": type_idx = array_get(what_idx, "type") - return what_is(type_idx) + return leave(what_idx, what_is(type_idx)) break default: type_idx = array_get(what_idx, "type") what_is(type_idx) break } - return 0 + return leave(what_idx, 0) } BEGIN { print "#include " -- 2.40.0