summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-07-24 10:51:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-07-24 17:19:29 (GMT)
commit26114c00be2cd49b97b18df69a909d3330886e9d (patch)
tree43da32d8a751ea7d022f1cb53f7b1eb732d509c8 /strbuf.c
parentc7d017d7e1cca37ca20f73c11fa9f1b319a2c3a5 (diff)
downloadgit-26114c00be2cd49b97b18df69a909d3330886e9d.zip
git-26114c00be2cd49b97b18df69a909d3330886e9d.tar.gz
git-26114c00be2cd49b97b18df69a909d3330886e9d.tar.bz2
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>
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/strbuf.c b/strbuf.c
index e79758b..6ff1f80 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -209,7 +209,7 @@ void strbuf_list_free(struct strbuf **sbs)
int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
{
- int len = a->len < b->len ? a->len: b->len;
+ size_t len = a->len < b->len ? a->len: b->len;
int cmp = memcmp(a->buf, b->buf, len);
if (cmp)
return cmp;
@@ -389,7 +389,7 @@ size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
{
- int i, len = src->len;
+ size_t i, len = src->len;
for (i = 0; i < len; i++) {
if (src->buf[i] == '%')
@@ -960,7 +960,7 @@ static size_t cleanup(char *line, size_t len)
*/
void strbuf_stripspace(struct strbuf *sb, int skip_comments)
{
- int empties = 0;
+ size_t empties = 0;
size_t i, j, len, newlen;
char *eol;