From 0899eb644fab415e9a3b304f53da9da50aaf91aa Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 28 Aug 2018 18:22:26 +0200 Subject: ui-ssdiff: ban strncpy() Git upstream bans strncpy() with commit: banned.h: mark strncpy() as banned e488b7aba743d23b830d239dcc33d9ca0745a9ad Signed-off-by: Christian Hesse --- ui-ssdiff.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ui-ssdiff.c') diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 68c2044..a3dd059 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -103,8 +103,7 @@ static int line_from_hunk(char *line, char type) return 0; len = buf2 - buf1; buf2 = xmalloc(len + 1); - strncpy(buf2, buf1, len); - buf2[len] = '\0'; + strlcpy(buf2, buf1, len + 1); res = atoi(buf2); free(buf2); return res; -- cgit v1.2.3-24-g4f1b From a96f2890f41e0b9b0ffa1bcdb1dddbef28c01662 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 28 Aug 2018 18:23:36 +0200 Subject: ui-ssdiff: ban strcat() Git upstream bans strcat() with commit: banned.h: mark strcat() as banned 1b11b64b815db62f93a04242e4aed5687a448748 Signed-off-by: Christian Hesse --- ui-ssdiff.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'ui-ssdiff.c') diff --git a/ui-ssdiff.c b/ui-ssdiff.c index a3dd059..c456033 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -117,6 +117,7 @@ static char *replace_tabs(char *line) int n_tabs = 0; int i; char *result; + int result_len; if (linelen == 0) { result = xmalloc(1); @@ -128,13 +129,14 @@ static char *replace_tabs(char *line) 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) { - strcat(result, prev_buf); + strncat(result, prev_buf, result_len); break; } else { strncat(result, prev_buf, cur_buf - prev_buf); -- cgit v1.2.3-24-g4f1b From 5bd7e9bc1b6749bbb5220d6c3a990469a7b839ae Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Thu, 21 Feb 2019 19:56:05 +0000 Subject: ui-ssdiff: resolve HTML5 validation errors - Remove ids from anchor elements. They were unusable because they were duplicated between files and versions of files. - Always close span, with html(). - Fix missing / on closing tr element in cgit_ssdiff_header_end(). Signed-off-by: Chris Mayo --- ui-ssdiff.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'ui-ssdiff.c') diff --git a/ui-ssdiff.c b/ui-ssdiff.c index c456033..b6dc5b0 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -207,11 +207,13 @@ static void print_part_with_lcs(char *class, char *line, char *lcs) } } else if (line[i] == lcs[j]) { same = 1; - htmlf(""); + html(""); j += 1; } html_txt(c); } + if (!same) + html(""); } static void print_ssdiff_line(char *class, @@ -236,7 +238,7 @@ static void print_ssdiff_line(char *class, char *fileurl = cgit_fileurl(ctx.repo->url, "tree", old_file->path, id_str); html("%s", lineno_str, lineno_str + 1); + htmlf("'>%s", lineno_str + 1); html(""); htmlf("", class); free(fileurl); @@ -259,7 +261,7 @@ static void print_ssdiff_line(char *class, char *fileurl = cgit_fileurl(ctx.repo->url, "tree", new_file->path, id_str); html("%s", lineno_str, lineno_str + 1); + htmlf("'>%s", lineno_str + 1); html(""); htmlf("", class); free(fileurl); @@ -405,7 +407,7 @@ void cgit_ssdiff_header_begin(void) void cgit_ssdiff_header_end(void) { - html(""); + html(""); } void cgit_ssdiff_footer(void) -- cgit v1.2.3-24-g4f1b From 68de710c1c0e9b823a156b1398643601a682fbf9 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 12 Feb 2019 21:53:02 +0100 Subject: ui-ssdiff: ban strncat() Git version v2.21.0 marks strncat() as banned (commit ace5707a803eda0f1dde3d776dc3729d3bc7759a), so replace it. Signed-off-by: Christian Hesse --- ui-ssdiff.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ui-ssdiff.c') diff --git a/ui-ssdiff.c b/ui-ssdiff.c index b6dc5b0..af8bc9e 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c @@ -117,7 +117,7 @@ static char *replace_tabs(char *line) int n_tabs = 0; int i; char *result; - int result_len; + size_t result_len; if (linelen == 0) { result = xmalloc(1); @@ -136,10 +136,12 @@ static char *replace_tabs(char *line) for (;;) { cur_buf = strchr(prev_buf, '\t'); if (!cur_buf) { - strncat(result, prev_buf, result_len); + linelen = strlen(result); + strlcpy(&result[linelen], prev_buf, result_len - linelen + 1); break; } else { - strncat(result, prev_buf, cur_buf - prev_buf); + linelen = strlen(result); + strlcpy(&result[linelen], prev_buf, cur_buf - prev_buf + 1); linelen = strlen(result); memset(&result[linelen], ' ', 8 - (linelen % 8)); result[linelen + 8 - (linelen % 8)] = '\0'; -- cgit v1.2.3-24-g4f1b