mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
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>
This commit is contained in:
parent
9c1a0df677
commit
c623fe5c21
5 changed files with 90 additions and 15 deletions
29
treesource.c
29
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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue