Skip to content
Myr

Fix integer overflow in row allocation. #60.

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

authored by antirez · committed by antirez · parent 0099562 · Browse files · 1 file+9 added−1 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+9 added−1 removed

  • other:+9 added−1 removed

1 file+9 added−1 removed

modified:kilo.c+9 added-1 removed
551 unmodified lines
552/* ======================= Editor rows implementation ======================= */553554/* Update the rendered version and the syntax highlight of a row. */555void editorUpdateRow(erow *row) {556 int tabs = 0, nonprint = 0, j, idx;556 unsigned int tabs = 0, nonprint = 0;557 int j, idx;558559 /* Create a version of the row we can directly print on the screen,560 * respecting tabs, substituting non printable characters with '?'. */561 free(row->render);562 for (j = 0; j < row->size; j++)563 if (row->chars[j] == TAB) tabs++;564565 unsigned long long allocsize =566 (unsigned long long) row->size + tabs*8 + nonprint*9 + 1;567 if (allocsize > UINT32_MAX) {568 printf("Some line of the edited file is too long for kilo\n");569 exit(1);570 }571572 row->render = malloc(row->size + tabs*8 + nonprint*9 + 1);573 idx = 0;574 for (j = 0; j < row->size; j++) {575 if (row->chars[j] == TAB) {
732 unmodified lines