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>
This commit is contained in:
19
ui-shared.c
19
ui-shared.c
@ -133,20 +133,25 @@ const char *cgit_repobasename(const char *reponame)
|
||||
static char rvbuf[1024];
|
||||
int p;
|
||||
const char *rv;
|
||||
strncpy(rvbuf, reponame, sizeof(rvbuf));
|
||||
if (rvbuf[sizeof(rvbuf)-1])
|
||||
size_t len;
|
||||
|
||||
len = strlcpy(rvbuf, reponame, sizeof(rvbuf));
|
||||
if (len >= sizeof(rvbuf))
|
||||
die("cgit_repobasename: truncated repository name '%s'", reponame);
|
||||
p = strlen(rvbuf)-1;
|
||||
p = len - 1;
|
||||
/* strip trailing slashes */
|
||||
while (p && rvbuf[p] == '/') rvbuf[p--] = 0;
|
||||
while (p && rvbuf[p] == '/')
|
||||
rvbuf[p--] = '\0';
|
||||
/* strip trailing .git */
|
||||
if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) {
|
||||
p -= 3; rvbuf[p--] = 0;
|
||||
p -= 3;
|
||||
rvbuf[p--] = '\0';
|
||||
}
|
||||
/* strip more trailing slashes if any */
|
||||
while ( p && rvbuf[p] == '/') rvbuf[p--] = 0;
|
||||
while (p && rvbuf[p] == '/')
|
||||
rvbuf[p--] = '\0';
|
||||
/* find last slash in the remaining string */
|
||||
rv = strrchr(rvbuf,'/');
|
||||
rv = strrchr(rvbuf, '/');
|
||||
if (rv)
|
||||
return ++rv;
|
||||
return rvbuf;
|
||||
|
Reference in New Issue
Block a user