aboutsummaryrefslogtreecommitdiff
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
-rw-r--r--shared.c7
-rw-r--r--ui-shared.c19
-rw-r--r--ui-ssdiff.c12
3 files changed, 15 insertions, 23 deletions
diff --git a/shared.c b/shared.c
index 609bd2a..f7b64cf 100644
--- a/shared.c
+++ b/shared.c
@@ -476,16 +476,15 @@ static int is_token_char(char c)
static char *expand_macro(char *name, int maxlength)
{
char *value;
- size_t len;
+ int len;
len = 0;
value = getenv(name);
if (value) {
- len = strlen(value) + 1;
+ len = strlen(value);
if (len > maxlength)
len = maxlength;
- strlcpy(name, value, len);
- --len;
+ strncpy(name, value, len);
}
return name + len;
}
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;
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
index 68c2044..7f261ed 100644
--- a/ui-ssdiff.c
+++ b/ui-ssdiff.c
@@ -114,10 +114,11 @@ static char *replace_tabs(char *line)
{
char *prev_buf = line;
char *cur_buf;
- size_t linelen = strlen(line);
+ int linelen = strlen(line);
int n_tabs = 0;
int i;
char *result;
+ char *spaces = " ";
if (linelen == 0) {
result = xmalloc(1);
@@ -125,23 +126,20 @@ 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';
- for (;;) {
+ while (1) {
cur_buf = strchr(prev_buf, '\t');
if (!cur_buf) {
strcat(result, prev_buf);
break;
} else {
strncat(result, prev_buf, cur_buf - prev_buf);
- linelen = strlen(result);
- memset(&result[linelen], ' ', 8 - (linelen % 8));
- result[linelen + 8 - (linelen % 8)] = '\0';
+ strncat(result, spaces, 8 - (strlen(result) % 8));
}
prev_buf = cur_buf + 1;
}