Skip to content

Commit

Permalink
fix(legacy): Fix split_message() to correctly handle strings that are…
Browse files Browse the repository at this point in the history
… not null-terminated.
  • Loading branch information
andrewkozlik committed Nov 10, 2021
1 parent d8de957 commit 0737dee
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions legacy/firmware/layout2.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,17 @@ const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen) {
if (rowlen > 32) {
rowlen = 32;
}

memzero(str, sizeof(str));
strlcpy(str[0], (char *)msg, rowlen + 1);
if (len > rowlen) {
strlcpy(str[1], (char *)msg + rowlen, rowlen + 1);
}
if (len > rowlen * 2) {
strlcpy(str[2], (char *)msg + rowlen * 2, rowlen + 1);
for (int i = 0; i < 4; ++i) {
size_t show_len = strnlen((char *)msg, MIN(rowlen, len));
memcpy(str[i], (char *)msg, show_len);
str[i][show_len] = '\0';
msg += show_len;
len -= show_len;
}
if (len > rowlen * 3) {
strlcpy(str[3], (char *)msg + rowlen * 3, rowlen + 1);
}
if (len > rowlen * 4) {

if (len > 0) {
str[3][rowlen - 1] = '.';
str[3][rowlen - 2] = '.';
str[3][rowlen - 3] = '.';
Expand Down

0 comments on commit 0737dee

Please sign in to comment.