diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2009-09-09 14:38:30 +1000 |
---|---|---|
committer | Jon Loeliger <jdl@jdl.com> | 2009-11-11 07:34:01 -0600 |
commit | c623fe5c21e0358fc38a4e8ddb0d51379f0733e8 (patch) | |
tree | 33852e9281cd5074304435f308f134261d5ddf48 /treesource.c | |
parent | 9c1a0df677bf0f4af622a404f6c738ad711326e0 (diff) | |
download | dtc-c623fe5c21e0358fc38a4e8ddb0d51379f0733e8.zip dtc-c623fe5c21e0358fc38a4e8ddb0d51379f0733e8.tar.gz dtc-c623fe5c21e0358fc38a4e8ddb0d51379f0733e8.tar.bz2 |
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 <david@gibson.dropbear.id.au>
Diffstat (limited to 'treesource.c')
-rw-r--r-- | treesource.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/treesource.c b/treesource.c index 1521ff1..cc1751d 100644 --- a/treesource.c +++ b/treesource.c @@ -63,26 +63,20 @@ static void write_propval_string(FILE *f, struct data val) { 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 *f, struct data val) break; 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)) |