Diffstat (limited to 'ui-shared.c')
| -rw-r--r-- | ui-shared.c | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/ui-shared.c b/ui-shared.c index 739505a..066a470 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -133,25 +133,20 @@ const char *cgit_repobasename(const char *reponame) static char rvbuf[1024]; int p; const char *rv; - size_t len; - - len = strlcpy(rvbuf, reponame, sizeof(rvbuf)); - if (len >= sizeof(rvbuf)) + strncpy(rvbuf, reponame, sizeof(rvbuf)); + if (rvbuf[sizeof(rvbuf)-1]) die("cgit_repobasename: truncated repository name '%s'", reponame); - p = len - 1; + p = strlen(rvbuf)-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; |