Skip to content

Commit 26114c0

Browse files
peffgitster
authored andcommitted
strbuf: use size_t for length in intermediate variables
A few strbuf functions store the length of a strbuf in a temporary variable. We should always use size_t for this, as it's possible for a strbuf to exceed an "int" (e.g., a 2GB string on a 64-bit system). This is unlikely in practice, but we should try to behave sensibly on silly or malicious input. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c7d017d commit 26114c0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

strbuf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void strbuf_list_free(struct strbuf **sbs)
209209

210210
int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
211211
{
212-
int len = a->len < b->len ? a->len: b->len;
212+
size_t len = a->len < b->len ? a->len: b->len;
213213
int cmp = memcmp(a->buf, b->buf, len);
214214
if (cmp)
215215
return cmp;
@@ -389,7 +389,7 @@ size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
389389

390390
void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
391391
{
392-
int i, len = src->len;
392+
size_t i, len = src->len;
393393

394394
for (i = 0; i < len; i++) {
395395
if (src->buf[i] == '%')
@@ -960,7 +960,7 @@ static size_t cleanup(char *line, size_t len)
960960
*/
961961
void strbuf_stripspace(struct strbuf *sb, int skip_comments)
962962
{
963-
int empties = 0;
963+
size_t empties = 0;
964964
size_t i, j, len, newlen;
965965
char *eol;
966966

0 commit comments

Comments
 (0)