about summary refs log tree commit diff stats
path: root/ui-ssdiff.c
diff options
context:
space:
mode:
authorJason A. Donenfeld2018-07-04 03:13:31 +0200
committerJason A. Donenfeld2018-07-04 03:13:41 +0200
commit08a2b1b8f812c6d77489467c8ff120979c297bed (patch)
tree68b95757d8f410a82b2f1bb01440cc7cf0e0ed63 /ui-ssdiff.c
parentcgitrc.5: document new signature notes (diff)
downloadcgit-08a2b1b8f812c6d77489467c8ff120979c297bed.tar.gz
cgit-08a2b1b8f812c6d77489467c8ff120979c297bed.zip
Fix gcc 8.1.1 compiler warnings
    CC ../shared.o
../shared.c: In function ‘expand_macro’:
../shared.c:487:3: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
   strncpy(name, value, len);
   ^~~~~~~~~~~~~~~~~~~~~~~~~
../shared.c:484:9: note: length computed here
   len = strlen(value);
         ^~~~~~~~~~~~~
../ui-shared.c: In function ‘cgit_repobasename’:
../ui-shared.c:136:2: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation]
  strncpy(rvbuf, reponame, sizeof(rvbuf));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CC ../ui-ssdiff.o
../ui-ssdiff.c: In function ‘replace_tabs’:
../ui-ssdiff.c:142:4: warning: ‘strncat’ output truncated copying between 1 and 8 bytes from a string of length 8 [-Wstringop-truncation]
    strncat(result, spaces, 8 - (strlen(result) % 8));
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
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 }