From fa928fba7e1ce94aef58798e77a9261192fdbb01 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 18 Jun 2014 22:49:43 +1000 Subject: [PATCH] Fix an off-by-2 error in the source output code This has been there for ages, but the assertion makes no sense in the context of the test immediately preceding it. This caused an abort() when in -I dts -O dts mode with the right sort of internal labels in a string property value. Add a testcase for this and another candidate edge case (though this one we already get right). Signed-off-by: David Gibson --- tests/run_tests.sh | 4 ++++ tests/sourceoutput.dts | 14 ++++++++++++++ treesource.c | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/sourceoutput.dts diff --git a/tests/run_tests.sh b/tests/run_tests.sh index c6adf21..f94d361 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -271,6 +271,10 @@ libfdt_tests () { # Specific bug tests run_test add_subnode_with_nops + run_dtc_test -I dts -O dts -o sourceoutput.test.dts sourceoutput.dts + run_dtc_test -I dts -O dtb -o sourceoutput.test.dtb sourceoutput.dts + run_dtc_test -I dts -O dtb -o sourceoutput.test.dts.test.dtb sourceoutput.test.dts + run_test dtbs_equal_ordered sourceoutput.test.dtb sourceoutput.test.dts.test.dtb } dtc_tests () { diff --git a/tests/sourceoutput.dts b/tests/sourceoutput.dts new file mode 100644 index 0000000..477762f --- /dev/null +++ b/tests/sourceoutput.dts @@ -0,0 +1,14 @@ +/dts-v1/; + +/ { + /* Some versions had an off-by-2 bug which caused an abort + * when outputing labels within strings like this in source + * format */ + prop1: prop1 = start1: "foo", mid1: "bar" end1: ; + + /* Make sure that we correctly handle source output of things + * which could almost be expressed as strings, except for the + * embedded labels */ + prop2 = start2: [66 6f 6f], mid2: "bar" end2: ; +}; + diff --git a/treesource.c b/treesource.c index bf7a626..3a87b9f 100644 --- a/treesource.c +++ b/treesource.c @@ -109,7 +109,7 @@ static void write_propval_string(FILE *f, struct data val) break; case '\0': fprintf(f, "\", "); - while (m && (m->offset < i)) { + while (m && (m->offset <= (i + 1))) { if (m->type == LABEL) { assert(m->offset == (i+1)); fprintf(f, "%s: ", m->ref);