[Crosstoolchain-logs] [device-tree-compiler] 152/357: dtc: Improve support for string escapes

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:06:08 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.3.x
in repository device-tree-compiler.

commit a756c12bea9e39acbed483d9008852f3a371e4a4
Author: David Gibson <david at gibson.dropbear.id.au>
Date:   Tue Oct 16 16:42:02 2007 +1000

    dtc: Improve support for string escapes
    
    dtc supports the use of C-style escapes (\n, \t and so forth) in
    string property definitions via the data_copy_escape_string()
    function.  However, while it supports the most common escape
    characters, it doesn't support the full set that C does, which is a
    potential gotcha.
    
    Worse, a bug in the lexer means that while data_copy_escape_string()
    can handle the \" escape, a string with such an escape won't lex
    correctly.
    
    This patch fixes both problems, extending data_copy_escape_string() to
    support the missing escapes, and fixing the regex for strings in the
    lexer to handle internal escaped quotes.
    
    This also adds a testcase for string escape functionality.
    
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 data.c                 | 12 ++++++++++++
 dtc-lexer.l            |  2 +-
 tests/Makefile.tests   |  3 ++-
 tests/escapes.dts      |  4 ++++
 tests/run_tests.sh     |  3 +++
 tests/string_escapes.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/testdata.h       |  1 +
 7 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/data.c b/data.c
index 1836f08..b8c79c1 100644
--- a/data.c
+++ b/data.c
@@ -150,12 +150,24 @@ struct data data_copy_escape_string(char *s, int len)
 		c = s[i++];
 		assert(c);
 		switch (c) {
+		case 'a':
+			q[d.len++] = '\a';
+			break;
+		case 'b':
+			q[d.len++] = '\b';
+			break;
 		case 't':
 			q[d.len++] = '\t';
 			break;
 		case 'n':
 			q[d.len++] = '\n';
 			break;
+		case 'v':
+			q[d.len++] = '\v';
+			break;
+		case 'f':
+			q[d.len++] = '\f';
+			break;
 		case 'r':
 			q[d.len++] = '\r';
 			break;
diff --git a/dtc-lexer.l b/dtc-lexer.l
index 08ed106..278a96e 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -69,7 +69,7 @@ REFCHAR		({PROPCHAR}|{UNITCHAR}|[/@])
 			}
 		}
 
-\"[^"]*\"	{
+\"([^\\"]|\\.)*\"	{
 			yylloc.filenum = srcpos_filenum;
 			yylloc.first_line = yylineno;
 			DPRINT("String: %s\n", yytext);
diff --git a/tests/Makefile.tests b/tests/Makefile.tests
index 3c3305b..78afc8d 100644
--- a/tests/Makefile.tests
+++ b/tests/Makefile.tests
@@ -7,7 +7,8 @@ LIB_TESTS_L = get_mem_rsv \
 	setprop_inplace nop_property nop_node \
 	sw_tree1 \
 	move_and_save \
-	open_pack rw_tree1 setprop del_property del_node
+	open_pack rw_tree1 setprop del_property del_node \
+	string_escapes
 LIB_TESTS = $(LIB_TESTS_L:%=$(TESTS_PREFIX)%)
 
 LIBTREE_TESTS_L = truncated_property
diff --git a/tests/escapes.dts b/tests/escapes.dts
new file mode 100644
index 0000000..236fe13
--- /dev/null
+++ b/tests/escapes.dts
@@ -0,0 +1,4 @@
+/ {
+	compatible = "test_string_escapes";
+	escape-str = "nastystring: \a\b\t\n\v\f\r\\\"\xff";
+};
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 0c2142f..e048b8f 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -104,6 +104,9 @@ dtc_tests () {
     run_test dtc.sh -f -I dts -O dtb -o dtc_tree1.test.dtb test_tree1.dts
     tree1_tests dtc_tree1.test.dtb
     tree1_tests_rw dtc_tree1.test.dtb
+
+    run_test dtc.sh -f -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
+    run_test string_escapes dtc_escapes.test.dtb
 }
 
 while getopts "vdt:" ARG ; do
diff --git a/tests/string_escapes.c b/tests/string_escapes.c
new file mode 100644
index 0000000..0238502
--- /dev/null
+++ b/tests/string_escapes.c
@@ -0,0 +1,42 @@
+/*
+ * libfdt - Flat Device Tree manipulation
+ *	Testcase for string escapes in dtc
+ * Copyright (C) 2006 David Gibson, IBM Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+
+#include <fdt.h>
+#include <libfdt.h>
+
+#include "tests.h"
+#include "testdata.h"
+
+int main(int argc, char *argv[])
+{
+	void *fdt;
+
+	test_init(argc, argv);
+	fdt = load_blob_arg(argc, argv);
+
+	check_getprop(fdt, 0, "escape-str",
+		      strlen(TEST_STRING_2)+1, TEST_STRING_2);
+
+	PASS();
+}
diff --git a/tests/testdata.h b/tests/testdata.h
index 3d08ff7..525177f 100644
--- a/tests/testdata.h
+++ b/tests/testdata.h
@@ -24,6 +24,7 @@
 #define TEST_VALUE_2	cell_to_fdt(0xabcd1234)
 
 #define TEST_STRING_1	"hello world"
+#define TEST_STRING_2	"nastystring: \a\b\t\n\v\f\r\\\"\xff"
 
 #ifndef __ASSEMBLY__
 extern struct fdt_header _test_tree1;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list