mobile/gui: Fix overlapping memcpy that trashed strings

This commit is contained in:
Andreas Eversberg 2016-09-25 08:09:38 +02:00
parent 2f5c76a994
commit c1dec9c2be
2 changed files with 10 additions and 10 deletions

View File

@ -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++;

View File

@ -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)