about summary refs log tree commit diff stats
path: root/ui-shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-shared.c')
-rw-r--r--ui-shared.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/ui-shared.c b/ui-shared.c index 066a470..739505a 100644 --- a/ui-shared.c +++ b/ui-shared.c
@@ -133,20 +133,25 @@ const char *cgit_repobasename(const char *reponame)
133 static char rvbuf[1024]; 133 static char rvbuf[1024];
134 int p; 134 int p;
135 const char *rv; 135 const char *rv;
136 strncpy(rvbuf, reponame, sizeof(rvbuf)); 136 size_t len;
137 if (rvbuf[sizeof(rvbuf)-1]) 137
138 len = strlcpy(rvbuf, reponame, sizeof(rvbuf));
139 if (len >= sizeof(rvbuf))
138 die("cgit_repobasename: truncated repository name '%s'", reponame); 140 die("cgit_repobasename: truncated repository name '%s'", reponame);
139 p = strlen(rvbuf)-1; 141 p = len - 1;
140 /* strip trailing slashes */ 142 /* strip trailing slashes */
141 while (p && rvbuf[p] == '/') rvbuf[p--] = 0; 143 while (p && rvbuf[p] == '/')
144 rvbuf[p--] = '\0';
142 /* strip trailing .git */ 145 /* strip trailing .git */
143 if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) { 146 if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) {
144 p -= 3; rvbuf[p--] = 0; 147 p -= 3;
148 rvbuf[p--] = '\0';
145 } 149 }
146 /* strip more trailing slashes if any */ 150 /* strip more trailing slashes if any */
147 while ( p && rvbuf[p] == '/') rvbuf[p--] = 0; 151 while (p && rvbuf[p] == '/')
152 rvbuf[p--] = '\0';
148 /* find last slash in the remaining string */ 153 /* find last slash in the remaining string */
149 rv = strrchr(rvbuf,'/'); 154 rv = strrchr(rvbuf, '/');
150 if (rv) 155 if (rv)
151 return ++rv; 156 return ++rv;
152 return rvbuf; 157 return rvbuf;