Skip to content
Myr

main: use realloc() when adding text to the prompt

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Eklöf · committed by Daniel Eklöf · parent 453ca3a · Browse files · 1 file+7 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−12 removed

  • other:+7 added−12 removed

1 file+7 added−12 removed

modified:main.c+7 added-12 removed
425 unmodified lines
426 cnd_signal(&c->repeat.cond);427 mtx_unlock(&c->repeat.mutex);428429 const size_t new_len = strlen(c->prompt.text) + count + 1;430 char *new_text = malloc(new_len);430 char *new_text = realloc(c->prompt.text, new_len);431 if (new_text == NULL)432 return;433432 /* Everything from old prompt, up to the cursor */433 memcpy(new_text, c->prompt.text, c->prompt.cursor);434 new_text[c->prompt.cursor] = '\0';434 memmove(&new_text[c->prompt.cursor + count],435 &new_text[c->prompt.cursor],436 strlen(c->prompt.text) - c->prompt.cursor + 1);437 memcpy(&new_text[c->prompt.cursor], buf, count);438436 /* New text just entered */437 strcat(new_text, buf);438439 /* Everything from old prompt, after cursor */440 strcat(new_text, &c->prompt.text[c->prompt.cursor]);441 new_text[new_len - 1] = '\0';442443 free(c->prompt.text);439 c->prompt.text = new_text;440 c->prompt.cursor += count;441442 LOG_DBG("prompt: \"%s\" (cursor=%zu, length=%zu)",
528 unmodified lines