devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] dtc: Simplify asm_emit_string() implementation
@ 2017-03-04 13:26 Nicolas Iooss
       [not found] ` <20170304132647.23286-1-nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Iooss @ 2017-03-04 13:26 UTC (permalink / raw)
  To: David Gibson, Jon Loeliger,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA
  Cc: Nicolas Iooss

Using %.*s format helps making asm_emit_string() not modify its "str"
parameter.

While at it, constify the "str" parameter of bin_emit_string() and
asm_emit_string(), as these function no longer modify it.

Signed-off-by: Nicolas Iooss <nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
---
 flattree.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/flattree.c b/flattree.c
index ebac548b3fa8..d8a118258e01 100644
--- a/flattree.c
+++ b/flattree.c
@@ -49,7 +49,7 @@ static struct version_info {
 
 struct emitter {
 	void (*cell)(void *, cell_t);
-	void (*string)(void *, char *, int);
+	void (*string)(void *, const char *, int);
 	void (*align)(void *, int);
 	void (*data)(void *, struct data);
 	void (*beginnode)(void *, struct label *labels);
@@ -64,7 +64,7 @@ static void bin_emit_cell(void *e, cell_t val)
 	*dtbuf = data_append_cell(*dtbuf, val);
 }
 
-static void bin_emit_string(void *e, char *str, int len)
+static void bin_emit_string(void *e, const char *str, int len)
 {
 	struct data *dtbuf = e;
 
@@ -144,22 +144,14 @@ static void asm_emit_cell(void *e, cell_t val)
 		(val >> 8) & 0xff, val & 0xff);
 }
 
-static void asm_emit_string(void *e, char *str, int len)
+static void asm_emit_string(void *e, const char *str, int len)
 {
 	FILE *f = e;
-	char c = 0;
 
-	if (len != 0) {
-		/* XXX: ewww */
-		c = str[len];
-		str[len] = '\0';
-	}
-
-	fprintf(f, "\t.string\t\"%s\"\n", str);
-
-	if (len != 0) {
-		str[len] = c;
-	}
+	if (len != 0)
+		fprintf(f, "\t.string\t\"%.*s\"\n", len, str);
+	else
+		fprintf(f, "\t.string\t\"%s\"\n", str);
 }
 
 static void asm_emit_align(void *e, int a)
-- 
2.11.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-03-09  1:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-04 13:26 [PATCH 1/5] dtc: Simplify asm_emit_string() implementation Nicolas Iooss
     [not found] ` <20170304132647.23286-1-nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
2017-03-04 13:26   ` [PATCH 2/5] libfdt: overlay: Check the value of the right variable Nicolas Iooss
     [not found]     ` <20170304132647.23286-2-nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
2017-03-08 21:01       ` Simon Glass
     [not found]         ` <CAPnjgZ2Lon3e-NV-FH76QpXFP2tAcc=Ex48hG7OMQxbcjzBfig-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-09  1:35           ` David Gibson
2017-03-04 13:26   ` [PATCH 3/5] tests: Make realloc_fdt() really allocate *fdt Nicolas Iooss
     [not found]     ` <20170304132647.23286-3-nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
2017-03-08 21:01       ` Simon Glass
     [not found]         ` <CAPnjgZ0=jfYeYZSZUeQRf00wyHaQwDBRYvqAQqO6Bu0B2VA5NA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2017-03-09  1:35           ` David Gibson
2017-03-04 13:26   ` [PATCH 4/5] fdtget: Use @return to document the return value Nicolas Iooss
     [not found]     ` <20170304132647.23286-4-nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
2017-03-08 21:01       ` Simon Glass
2017-03-04 13:26   ` [PATCH 5/5] fdtput: Remove star from value_len documentation Nicolas Iooss
     [not found]     ` <20170304132647.23286-5-nicolas.iooss_linux-oWGTIYur0i8@public.gmane.org>
2017-03-08 21:01       ` Simon Glass
2017-03-06  4:13   ` [PATCH 1/5] dtc: Simplify asm_emit_string() implementation David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).