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>
Jeff King committed
Jul 24, 2018 at 06:51 UTC
26114c00be2cd49b97b18df69a909d3330886e9d
1 file changed
+3
-3
strbuf.c
+3
-3
@@ -209,7 +209,7 @@ void strbuf_list_free(struct strbuf **sbs)
209
210
int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
211
{
212
- int len = a->len < b->len ? a->len: b->len;
212
+ size_t len = a->len < b->len ? a->len: b->len;
213
int cmp = memcmp(a->buf, b->buf, len);
214
if (cmp)
215
return cmp;
@@ -389,7 +389,7 @@ size_t strbuf_expand_dict_cb(struct strbuf *sb, const char *placeholder,
389
390
void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src)
391
{
392
- int i, len = src->len;
392
+ size_t i, len = src->len;
393
394
for (i = 0; i < len; i++) {
395
if (src->buf[i] == '%')
@@ -960,7 +960,7 @@ static size_t cleanup(char *line, size_t len)
960
*/
961
void strbuf_stripspace(struct strbuf *sb, int skip_comments)
962
{
963
- int empties = 0;
963
+ size_t empties = 0;
964
size_t i, j, len, newlen;
965
char *eol;
966