Make sure memory can be filled with a string
... and not just the last character
This commit is contained in:
parent
795dd91575
commit
17b67da03e
13
src/term.c
13
src/term.c
|
@ -422,10 +422,15 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
for (i = start_offset; i < len + start_offset; i++) {
|
for (i = start_offset; i < len + start_offset; i++) {
|
||||||
data.is_float = false;
|
data.is_float = false;
|
||||||
data.size = 0;
|
data.size = 0;
|
||||||
data.str_ptr = NULL;
|
|
||||||
|
|
||||||
// Handle the next argument
|
// Handle the next argument
|
||||||
if (i < argc - start_offset + 3) {
|
if (i < argc - start_offset + 3) {
|
||||||
|
// Free string pointer if already allocated
|
||||||
|
if(data.str_ptr) {
|
||||||
|
free(data.str_ptr);
|
||||||
|
data.str_ptr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Get suffix if present
|
// Get suffix if present
|
||||||
char suffix = argv[i][strlen(argv[i]) - 1];
|
char suffix = argv[i][strlen(argv[i]) - 1];
|
||||||
char lsuffix = argv[i][strlen(argv[i]) - 2];
|
char lsuffix = argv[i][strlen(argv[i]) - 2];
|
||||||
|
@ -474,6 +479,8 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
avrdude_message(MSG_INFO, "\n%s (write): can't parse data '%s'\n",
|
avrdude_message(MSG_INFO, "\n%s (write): can't parse data '%s'\n",
|
||||||
progname, argv[i]);
|
progname, argv[i]);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
if(data.str_ptr != NULL)
|
||||||
|
free(data.str_ptr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,7 +520,6 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
if(data.str_ptr) {
|
if(data.str_ptr) {
|
||||||
for(int16_t j = 0; j < strlen(data.str_ptr); j++)
|
for(int16_t j = 0; j < strlen(data.str_ptr); j++)
|
||||||
buf[i - start_offset + data.bytes_grown++] = (uint8_t)data.str_ptr[j];
|
buf[i - start_offset + data.bytes_grown++] = (uint8_t)data.str_ptr[j];
|
||||||
free(data.str_ptr);
|
|
||||||
} else {
|
} else {
|
||||||
buf[i - start_offset + data.bytes_grown] = data.a[0];
|
buf[i - start_offset + data.bytes_grown] = data.a[0];
|
||||||
if (llabs(data.ll) > 0x000000FF || data.size >= 2 || data.is_float)
|
if (llabs(data.ll) > 0x000000FF || data.size >= 2 || data.is_float)
|
||||||
|
@ -543,6 +549,9 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data.str_ptr)
|
||||||
|
free(data.str_ptr);
|
||||||
|
|
||||||
avrdude_message(MSG_NOTICE, "\nInfo: Writing %d bytes starting from address 0x%02x",
|
avrdude_message(MSG_NOTICE, "\nInfo: Writing %d bytes starting from address 0x%02x",
|
||||||
len + data.bytes_grown, addr);
|
len + data.bytes_grown, addr);
|
||||||
if (write_mode == WRITE_MODE_FILL)
|
if (write_mode == WRITE_MODE_FILL)
|
||||||
|
|
Loading…
Reference in New Issue