ui-ssdiff: ban strcat()

Git upstream bans strcat() with commit:

  banned.h: mark strcat() as banned
  1b11b64b815db62f93a04242e4aed5687a448748

Signed-off-by: Christian Hesse <mail@eworm.de>
This commit is contained in:
Christian Hesse 2018-08-28 18:23:36 +02:00
parent 0899eb644f
commit a96f2890f4

View File

@ -117,6 +117,7 @@ static char *replace_tabs(char *line)
int n_tabs = 0; int n_tabs = 0;
int i; int i;
char *result; char *result;
int result_len;
if (linelen == 0) { if (linelen == 0) {
result = xmalloc(1); result = xmalloc(1);
@ -128,13 +129,14 @@ static char *replace_tabs(char *line)
if (line[i] == '\t') if (line[i] == '\t')
n_tabs += 1; n_tabs += 1;
} }
result = xmalloc(linelen + n_tabs * 8 + 1); result_len = linelen + n_tabs * 8;
result = xmalloc(result_len + 1);
result[0] = '\0'; result[0] = '\0';
for (;;) { for (;;) {
cur_buf = strchr(prev_buf, '\t'); cur_buf = strchr(prev_buf, '\t');
if (!cur_buf) { if (!cur_buf) {
strcat(result, prev_buf); strncat(result, prev_buf, result_len);
break; break;
} else { } else {
strncat(result, prev_buf, cur_buf - prev_buf); strncat(result, prev_buf, cur_buf - prev_buf);