diff options
-rw-r--r-- | shared.c | 7 | ||||
-rw-r--r-- | ui-shared.c | 19 | ||||
-rw-r--r-- | ui-ssdiff.c | 12 |
3 files changed, 23 insertions, 15 deletions
diff --git a/shared.c b/shared.c index f7b64cf..609bd2a 100644 --- a/shared.c +++ b/shared.c | |||
@@ -476,15 +476,16 @@ static int is_token_char(char c) | |||
476 | static char *expand_macro(char *name, int maxlength) | 476 | static char *expand_macro(char *name, int maxlength) |
477 | { | 477 | { |
478 | char *value; | 478 | char *value; |
479 | int len; | 479 | size_t len; |
480 | 480 | ||
481 | len = 0; | 481 | len = 0; |
482 | value = getenv(name); | 482 | value = getenv(name); |
483 | if (value) { | 483 | if (value) { |
484 | len = strlen(value); | 484 | len = strlen(value) + 1; |
485 | if (len > maxlength) | 485 | if (len > maxlength) |
486 | len = maxlength; | 486 | len = maxlength; |
487 | strncpy(name, value, len); | 487 | strlcpy(name, value, len); |
488 | --len; | ||
488 | } | 489 | } |
489 | return name + len; | 490 | return name + len; |
490 | } | 491 | } |
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; |
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) | |||
114 | { | 114 | { |
115 | char *prev_buf = line; | 115 | char *prev_buf = line; |
116 | char *cur_buf; | 116 | char *cur_buf; |
117 | int linelen = strlen(line); | 117 | size_t linelen = strlen(line); |
118 | int n_tabs = 0; | 118 | int n_tabs = 0; |
119 | int i; | 119 | int i; |
120 | char *result; | 120 | char *result; |
121 | char *spaces = " "; | ||
122 | 121 | ||
123 | if (linelen == 0) { | 122 | if (linelen == 0) { |
124 | result = xmalloc(1); | 123 | result = xmalloc(1); |
@@ -126,20 +125,23 @@ static char *replace_tabs(char *line) | |||
126 | return result; | 125 | return result; |
127 | } | 126 | } |
128 | 127 | ||
129 | for (i = 0; i < linelen; i++) | 128 | for (i = 0; i < linelen; i++) { |
130 | if (line[i] == '\t') | 129 | if (line[i] == '\t') |
131 | n_tabs += 1; | 130 | n_tabs += 1; |
131 | } | ||
132 | result = xmalloc(linelen + n_tabs * 8 + 1); | 132 | result = xmalloc(linelen + n_tabs * 8 + 1); |
133 | result[0] = '\0'; | 133 | result[0] = '\0'; |
134 | 134 | ||
135 | while (1) { | 135 | for (;;) { |
136 | cur_buf = strchr(prev_buf, '\t'); | 136 | cur_buf = strchr(prev_buf, '\t'); |
137 | if (!cur_buf) { | 137 | if (!cur_buf) { |
138 | strcat(result, prev_buf); | 138 | strcat(result, prev_buf); |
139 | break; | 139 | break; |
140 | } else { | 140 | } else { |
141 | strncat(result, prev_buf, cur_buf - prev_buf); | 141 | strncat(result, prev_buf, cur_buf - prev_buf); |
142 | strncat(result, spaces, 8 - (strlen(result) % 8)); | 142 | linelen = strlen(result); |
143 | memset(&result[linelen], ' ', 8 - (linelen % 8)); | ||
144 | result[linelen + 8 - (linelen % 8)] = '\0'; | ||
143 | } | 145 | } |
144 | prev_buf = cur_buf + 1; | 146 | prev_buf = cur_buf + 1; |
145 | } | 147 | } |