Skip to content

Commit 6c3ace7

Browse files
committed
eepmake: Close string blobs earlier to avoid errors
Finish the current data blob at the end of the current string, to avoid accidentally picking up following lines as hex data. Signed-off-by: Phil Elwell <[email protected]>
1 parent a2408f0 commit 6c3ace7

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

eeptools/eepmake.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ static void add_data_byte(int byte)
118118
data_blob->data[data_blob->dlen++] = byte;
119119
}
120120

121+
static void finish_data(void)
122+
{
123+
if (data_blob)
124+
{
125+
data_blob->data = realloc(data_blob->data, data_blob->dlen);
126+
data_blob = NULL;
127+
data_cap = 0;
128+
}
129+
}
130+
121131
static int parse_string(const char *p)
122132
{
123133
/* Read string data, stopping at escaped-doublequote */
@@ -140,6 +150,7 @@ static int parse_string(const char *p)
140150
else if (c2 == '"')
141151
{
142152
in_string = false;
153+
finish_data();
143154
break;
144155
}
145156
else
@@ -178,7 +189,10 @@ static int parse_data(char *c)
178189
{
179190
int byte = *(++j);
180191
if (byte == '"')
192+
{
193+
finish_data();
181194
return 0;
195+
}
182196
if (!isprint(byte))
183197
fatal_error("Bad character 0x%02x in simple string '%s'", byte, c);
184198
add_data_byte(byte);
@@ -236,16 +250,6 @@ struct var_blob_t *add_custom_blob(void)
236250
return blob;
237251
}
238252

239-
static void finish_data(void)
240-
{
241-
if (data_blob)
242-
{
243-
data_blob->data = realloc(data_blob->data, data_blob->dlen);
244-
data_blob = NULL;
245-
data_cap = 0;
246-
}
247-
}
248-
249253
static int parse_command(char *cmd, char *c)
250254
{
251255
int val;

0 commit comments

Comments
 (0)