Fix bug in -Odts with properties containing multiple terminating nulls
When in -Odts mode, dtc will not produce correct output for string-like properties which have more than one \0 character at the end of the property's bytestring. In fact, it generates output which is not syntactically correct. This patch fixes the bug, and adds a testcase for future regressions here.
Signed-off-by David Gibson <[email protected]>
tests/Makefile.tests +1 -0
@@ -11,6 +11,7 @@ LIB_TESTS_L = get_mem_rsv \ move_and_save mangle-layout nopulate \ open_pack rw_tree1 set_name setprop del_property del_node \ string_escapes references path-references boot-cpuid incbin \ + extra-terminating-null \ dtbs_equal_ordered \ add_subnode_with_nops path_offset_aliases LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
tests/extra-terminating-null.c new file +59 -0
59 lines not on this page · raw message
tests/extra-terminating-null.dts new file +11 -0
@@ -0,0 +1,11 @@ +/dts-v1/; + +/ { + extranull0 = "hello world"; + extranull1,1 = "hello world\0"; + extranull1,2 = "hello world", ""; + extranull2,1 = "hello world\0\0"; + extranull2,2 = "hello world", "", ""; + extranull2,3 = "hello world\0", ""; + extranull2,4 = "hello world", "\0"; +};
tests/run_tests.sh +4 -1
@@ -204,6 +204,9 @@ dtc_tests () { run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts run_test string_escapes dtc_escapes.test.dtb + run_dtc_test -I dts -O dtb -o dtc_extra-terminating-null.test.dtb extra-terminating-null.dts + run_test extra-terminating-null dtc_extra-terminating-null.test.dtb + run_dtc_test -I dts -O dtb -o dtc_references.test.dtb references.dts run_test references dtc_references.test.dtb
@@ -253,7 +256,7 @@ dtc_tests () { # Check -Odts mode preserve all dtb information for tree in test_tree1.dtb dtc_tree1.test.dtb dtc_escapes.test.dtb \ - dtc_references.test.dtb; do + dtc_extra-terminating-null.test.dtb dtc_references.test.dtb; do run_dtc_test -I dtb -O dts -o odts_$tree.test.dts $tree run_dtc_test -I dts -O dtb -o odts_$tree.test.dtb odts_$tree.test.dts run_test dtbs_equal_ordered $tree odts_$tree.test.dtb
treesource.c +15 -14
@@ -63,26 +63,20 @@ static void write_propval_string(FILE *f {const char *str = val.val;int i; -int newchunk =1 ;struct marker *m = val.markers;assert (str[val.len-1 ] =='\0' ); +while (m && (m->offset ==0 )) { +if (m->type ==LABEL ) +fprintf (f,"%s: " , m->ref); + m = m->next; + } +fprintf (f,"\"" ); +for (i =0 ; i < (val.len-1 ); i++) {char c = str[i]; -if (newchunk) { -while (m && (m->offset <= i)) { -if (m->type ==LABEL ) { -assert (m->offset == i); -fprintf (f,"%s: " , m->ref); - } - m = m->next; - } -fprintf (f,"\"" ); - newchunk =0 ; - } -switch (c) {case '\a' :fprintf (f,"\\a" );
@@ -113,7 +107,14 @@ static void write_propval_string(FILE *fbreak ;case '\0' :fprintf (f,"\", " ); - newchunk =1 ; +while (m && (m->offset < i)) { +if (m->type ==LABEL ) { +assert (m->offset == (i+1 )); +fprintf (f,"%s: " , m->ref); + } + m = m->next; + } +fprintf (f,"\"" );break ;default :if (isprint (c))
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson