Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.zx2c4.com/cgit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-07-04 04:13:31 +0300
committerJason A. Donenfeld <Jason@zx2c4.com>2018-07-04 04:13:41 +0300
commit08a2b1b8f812c6d77489467c8ff120979c297bed (patch)
tree68b95757d8f410a82b2f1bb01440cc7cf0e0ed63 /ui-ssdiff.c
parentc4167cbd65acef801e6132ba1182f6ce246ed630 (diff)
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)
{
char *prev_buf = line;
char *cur_buf;
- int linelen = strlen(line);
+ size_t linelen = strlen(line);
int n_tabs = 0;
int i;
char *result;
- char *spaces = " ";
if (linelen == 0) {
result = xmalloc(1);
@@ -126,20 +125,23 @@ static char *replace_tabs(char *line)
return result;
}
- for (i = 0; i < linelen; i++)
+ for (i = 0; i < linelen; i++) {
if (line[i] == '\t')
n_tabs += 1;
+ }
result = xmalloc(linelen + n_tabs * 8 + 1);
result[0] = '\0';
- while (1) {
+ for (;;) {
cur_buf = strchr(prev_buf, '\t');
if (!cur_buf) {
strcat(result, prev_buf);
break;
} else {
strncat(result, prev_buf, cur_buf - prev_buf);
- strncat(result, spaces, 8 - (strlen(result) % 8));
+ linelen = strlen(result);
+ memset(&result[linelen], ' ', 8 - (linelen % 8));
+ result[linelen + 8 - (linelen % 8)] = '\0';
}
prev_buf = cur_buf + 1;
}