Skip to content

Commit

Permalink
Replace use of strncat in scroll.cc with strcat (#1950)
Browse files Browse the repository at this point in the history
pwithcolors is allocated based on computed length so strncat produces a
warning.

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Jun 1, 2024
1 parent 2f7a31c commit 9358f56
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/scroll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ void print_scroll(struct text_object *obj, char *p, unsigned int p_max_size) {
}

int pwithcolors_len = strlen(p) + 4 + colorchanges - visibcolorchanges;
char *pwithcolors = static_cast<char *>(malloc(pwithcolors_len));
char *pwithcolors = new char[pwithcolors_len];

for (j = 0; j < frontcolorchanges; j++) { pwithcolors[j] = SPECIAL_CHAR; }
pwithcolors[j] = 0;
strncat(pwithcolors, p, pwithcolors_len);
strcat(pwithcolors, p);
unsigned int strend = strlen(pwithcolors);
// and place the colorchanges not in front or in the visible part behind the
// visible part
Expand All @@ -284,7 +284,7 @@ void print_scroll(struct text_object *obj, char *p, unsigned int p_max_size) {
}
pwithcolors[strend + j] = 0;
strncpy(p, pwithcolors, p_max_size);
free(pwithcolors);
delete[] pwithcolors;

// scroll
if (sd->direction == SCROLL_LEFT) {
Expand Down

0 comments on commit 9358f56

Please sign in to comment.