about summary refs log tree commit diff stats
path: root/ui-ssdiff.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-ssdiff.c')
-rw-r--r--ui-ssdiff.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/ui-ssdiff.c b/ui-ssdiff.c index 7f261ed..68c2044 100644 --- a/ui-ssdiff.c +++ b/ui-ssdiff.c
@@ -114,11 +114,10 @@ static char *replace_tabs(char *line)
114{ 114{
115 char *prev_buf = line; 115 char *prev_buf = line;
116 char *cur_buf; 116 char *cur_buf;
117 int linelen = strlen(line); 117 size_t linelen = strlen(line);
118 int n_tabs = 0; 118 int n_tabs = 0;
119 int i; 119 int i;
120 char *result; 120 char *result;
121 char *spaces = " ";
122 121
123 if (linelen == 0) { 122 if (linelen == 0) {
124 result = xmalloc(1); 123 result = xmalloc(1);
@@ -126,20 +125,23 @@ static char *replace_tabs(char *line)
126 return result; 125 return result;
127 } 126 }
128 127
129 for (i = 0; i < linelen; i++) 128 for (i = 0; i < linelen; i++) {
130 if (line[i] == '\t') 129 if (line[i] == '\t')
131 n_tabs += 1; 130 n_tabs += 1;
131 }
132 result = xmalloc(linelen + n_tabs * 8 + 1); 132 result = xmalloc(linelen + n_tabs * 8 + 1);
133 result[0] = '\0'; 133 result[0] = '\0';
134 134
135 while (1) { 135 for (;;) {
136 cur_buf = strchr(prev_buf, '\t'); 136 cur_buf = strchr(prev_buf, '\t');
137 if (!cur_buf) { 137 if (!cur_buf) {
138 strcat(result, prev_buf); 138 strcat(result, prev_buf);
139 break; 139 break;
140 } else { 140 } else {
141 strncat(result, prev_buf, cur_buf - prev_buf); 141 strncat(result, prev_buf, cur_buf - prev_buf);
142 strncat(result, spaces, 8 - (strlen(result) % 8)); 142 linelen = strlen(result);
143 memset(&result[linelen], ' ', 8 - (linelen % 8));
144 result[linelen + 8 - (linelen % 8)] = '\0';
143 } 145 }
144 prev_buf = cur_buf + 1; 146 prev_buf = cur_buf + 1;
145 } 147 }