From c1dec9c2be8bd3392814547b5e3d3dd5f9b71c5e Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 25 Sep 2016 08:09:38 +0200 Subject: mobile/gui: Fix overlapping memcpy that trashed strings --- src/host/layer23/src/mobile/gui.c | 12 ++++++------ src/host/layer23/src/ui/ui.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/host/layer23/src/mobile/gui.c b/src/host/layer23/src/mobile/gui.c index 6f354ac9..2ac7e403 100644 --- a/src/host/layer23/src/mobile/gui.c +++ b/src/host/layer23/src/mobile/gui.c @@ -117,7 +117,7 @@ static int status_netname(struct osmocom_ms *ms, char *text) len = strlen(text); if (len + 1 < UI_COLS) { shift = (UI_COLS - len) / 2; - memcpy(text + shift, text, len + 1); + memmove(text + shift, text, len + 1); memset(text, ' ', shift); } @@ -150,7 +150,7 @@ static int status_imsi(struct osmocom_ms *ms, char *text) len = strlen(text); /* wrap */ if (len > UI_COLS) { - memcpy(text + UI_COLS + 1, text + UI_COLS, len - UI_COLS + 1); + memmove(text + UI_COLS + 1, text + UI_COLS, len - UI_COLS + 1); text[UI_COLS] = '\0'; text[2 * UI_COLS + 1] = '\0'; @@ -169,7 +169,7 @@ static int status_imei(struct osmocom_ms *ms, char *text) len = strlen(text); /* wrap */ if (len > UI_COLS) { - memcpy(text + UI_COLS + 1, text + UI_COLS, len - UI_COLS + 1); + memmove(text + UI_COLS + 1, text + UI_COLS, len - UI_COLS + 1); text[UI_COLS] = '\0'; text[2 * UI_COLS + 1] = '\0'; @@ -1812,7 +1812,7 @@ int gui_notify_call(struct osmocom_ms *ms) len = strlen(p); if (len + 1 < UI_COLS) { shift = (UI_COLS - len) / 2; - memcpy(p + shift, p, len + 1); + memmove(p + shift, p, len + 1); memset(p, ' ', shift); } gui->status_lines[j] = p; @@ -1888,13 +1888,13 @@ int gui_notify_call(struct osmocom_ms *ms) /* if only one call */ if (calls == 1) { /* insert space above call state */ - memcpy(gui->status_lines + 1, gui->status_lines, + memmove(gui->status_lines + 1, gui->status_lines, j * sizeof(char *)); gui->status_lines[0] = ""; j++; if (j > 2) { /* insert space below call state */ - memcpy(gui->status_lines + 3, gui->status_lines + 2, + memmove(gui->status_lines + 3, gui->status_lines + 2, (j - 2) * sizeof(char *)); gui->status_lines[2] = ""; j++; diff --git a/src/host/layer23/src/ui/ui.c b/src/host/layer23/src/ui/ui.c index fbed986c..b5d01007 100644 --- a/src/host/layer23/src/ui/ui.c +++ b/src/host/layer23/src/ui/ui.c @@ -37,7 +37,7 @@ static char *ui_center(const char *text) len = strlen(line); if (len + 1 < UI_COLS) { shift = (UI_COLS - len) / 2; - memcpy(line + shift, line, len + 1); + memmove(line + shift, line, len + 1); memset(line, ' ', shift); } @@ -146,7 +146,7 @@ static int bottom_puts(struct ui_inst *ui, const char *text) if ((p = strchr(bottom_line, ' ')) && (space = UI_COLS - strlen(bottom_line))) { p++; - memcpy(p + space, p, strlen(p)); + memmove(p + space, p, strlen(p)); memset(p, ' ', space); } @@ -410,7 +410,7 @@ static int keypad_stringview(struct ui_inst *ui, struct ui_view *uv, ud->stringview.number[ud->stringview.pos] = '\0'; } else { /* insert digit */ - memcpy(ud->stringview.number + ud->stringview.pos + 1, + memmove(ud->stringview.number + ud->stringview.pos + 1, ud->stringview.number + ud->stringview.pos, strlen(ud->stringview.number + ud->stringview.pos) @@ -447,7 +447,7 @@ static int keypad_stringview(struct ui_inst *ui, struct ui_view *uv, ud->stringview.number[ud->stringview.pos] = '\0'; } else { /* remove digit */ - memcpy(ud->stringview.number + ud->stringview.pos - 1, + memmove(ud->stringview.number + ud->stringview.pos - 1, ud->stringview.number + ud->stringview.pos, strlen(ud->stringview.number + ud->stringview.pos) -- cgit v1.2.3