]> git.cameronkatri.com Git - cgit.git/commitdiff
ui-ssdiff: ban strcat()
authorChristian Hesse <mail@eworm.de>
Tue, 28 Aug 2018 16:23:36 +0000 (18:23 +0200)
committerChristian Hesse <mail@eworm.de>
Tue, 11 Sep 2018 06:47:12 +0000 (08:47 +0200)
Git upstream bans strcat() with commit:

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

Signed-off-by: Christian Hesse <mail@eworm.de>
ui-ssdiff.c

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