diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Harden the page renderers
Diffstat (limited to '')
-rw-r--r--source/ui-ssdiff.c46
1 file changed, 22 insertions, 24 deletions
diff --git a/source/ui-ssdiff.c b/source/ui-ssdiff.c
index 2ea4751..ad543f4 100644
--- a/source/ui-ssdiff.c
+++ b/source/ui-ssdiff.c
@@ -14,10 +14,6 @@
#include "ui-shared.h"
#include "ui-ssdiff.h"
-// The stylesheet sets no tab-size and tabs are expanded here rather than left
-// to the browser, so this has to be the width a browser would pick on its own.
-#define TAB_WIDTH 8
-
// One line held back until its run ends, owning the copy taken of it.
struct deferred_line {
int line_no;
@@ -90,13 +86,13 @@ static char *longest_common_subsequence(const char *old_line, const char *new_li
while (i < old_len && j < new_len) {
if (old_line[i] == new_line[j]) {
lcs[pos] = old_line[i];
- pos += 1;
- i += 1;
- j += 1;
+ pos++;
+ i++;
+ j++;
} else if (lcs_table[i + 1][j] >= lcs_table[i][j + 1]) {
- i += 1;
+ i++;
} else {
- j += 1;
+ j++;
}
}
@@ -143,9 +139,9 @@ static void print_line_with_lcs(const char *class, const char *line, const char
for (i = 0; i < len; i++) {
if (in_common) {
- if (line[i] == lcs[matched])
- matched += 1;
- else {
+ if (line[i] == lcs[matched]) {
+ matched++;
+ } else {
in_common = 0;
flush_run(&run);
htmlf("<span class='%s'>", class);
@@ -154,7 +150,7 @@ static void print_line_with_lcs(const char *class, const char *line, const char
in_common = 1;
flush_run(&run);
html("</span>");
- matched += 1;
+ matched++;
}
strbuf_addch(&run, line[i]);
}
@@ -202,10 +198,11 @@ static void print_row(const char *class, int old_line_no, char *old_line,
if (old_line_no > 0) {
print_lineno_cell(cgit_get_current_old_file(), old_rev_oid, old_line_no);
htmlf("<td class='%s'>", class);
- } else if (old_line)
+ } else if (old_line) {
htmlf("<td class='lineno'></td><td class='%s'>", class);
- else
+ } else {
htmlf("<td class='lineno'></td><td class='%s_dark'>", class);
+ }
if (old_line) {
if (lcs)
print_line_with_lcs("del", old_line, lcs);
@@ -217,10 +214,11 @@ static void print_row(const char *class, int old_line_no, char *old_line,
if (new_line_no > 0) {
print_lineno_cell(cgit_get_current_new_file(), new_rev_oid, new_line_no);
htmlf("<td class='%s'>", class);
- } else if (new_line)
+ } else if (new_line) {
htmlf("<td class='lineno'></td><td class='%s'>", class);
- else
+ } else {
htmlf("<td class='lineno'></td><td class='%s_dark'>", class);
+ }
if (new_line) {
if (lcs)
print_line_with_lcs("add", new_line, lcs);
@@ -264,7 +262,7 @@ static int count_deferred(struct deferred_line *item)
int count = 0;
while (item) {
- count += 1;
+ count++;
item = item->next;
}
return count;
@@ -342,9 +340,9 @@ static int hunk_start_line(const char *hunk, char marker)
long line_no;
p = strchr(hunk, marker);
- if (p == NULL)
+ if (!p)
return 0;
- p += 1;
+ p++;
line_no = strtol(p, NULL, 10);
if (line_no < 0 || line_no > INT_MAX)
return 0;
@@ -383,14 +381,14 @@ void cgit_ssdiff_line_cb(char *line, int len)
if (line[0] == ' ') {
print_deferred_lines();
print_row("ctx", current_old_line, line, current_new_line, line, 0);
- current_old_line += 1;
- current_new_line += 1;
+ current_old_line++;
+ current_new_line++;
} else if (line[0] == '+') {
defer_line(&deferred_new, &deferred_new_last, line, current_new_line);
- current_new_line += 1;
+ current_new_line++;
} else if (line[0] == '-') {
defer_line(&deferred_old, &deferred_old_last, line, current_old_line);
- current_old_line += 1;
+ current_old_line++;
} else if (line[0] == '@') {
html("<tr><td colspan='4' class='hunk'>");
html_txt(line);