]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reencode_string: use size_t for string lengths
authorJeff King <peff@peff.net>
Tue, 24 Jul 2018 10:50:33 +0000 (06:50 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Jul 2018 17:19:29 +0000 (10:19 -0700)
The iconv interface takes a size_t, which is the appropriate
type for an in-memory buffer. But our reencode_string_*
functions use integers, meaning we may get confusing results
when the sizes exceed INT_MAX. Let's use size_t
consistently.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
convert.c
pretty.c
strbuf.c
utf8.c
utf8.h

index 64d0d30e08de4acd496bf955d9ce64afa0ff5b8b..e012959b4cea7d4d10535918d868c0a5be591997 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -389,7 +389,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
                         struct strbuf *buf, const char *enc, int conv_flags)
 {
        char *dst;
-       int dst_len;
+       size_t dst_len;
        int die_on_error = conv_flags & CONV_WRITE_OBJECT;
 
        /*
@@ -452,7 +452,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
         */
        if (die_on_error && check_roundtrip(enc)) {
                char *re_src;
-               int re_src_len;
+               size_t re_src_len;
 
                re_src = reencode_string_len(dst, dst_len,
                                             enc, default_encoding,
@@ -480,7 +480,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
                              struct strbuf *buf, const char *enc)
 {
        char *dst;
-       int dst_len;
+       size_t dst_len;
 
        /*
         * No encoding is specified or there is nothing to encode.
index 703fa6ff7bf297e9d0dd91586f951f715032e06a..e1e4060243ccff33c1af820cdfc1fe2955e57e0f 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1538,7 +1538,7 @@ void format_commit_message(const struct commit *commit,
        }
 
        if (output_enc) {
-               int outsz;
+               size_t outsz;
                char *out = reencode_string_len(sb->buf, sb->len,
                                                output_enc, utf8, &outsz);
                if (out)
index b0716ac585285a971c04952254c34a00aab9f0ef..e79758b9420a6f9eafce3ddebe156e87c7663076 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -134,7 +134,7 @@ void strbuf_ltrim(struct strbuf *sb)
 int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
 {
        char *out;
-       int len;
+       size_t len;
 
        if (same_encoding(from, to))
                return 0;
diff --git a/utf8.c b/utf8.c
index a2fd24c70a22bd33d3d9f96460b9e52c8ac9fbf3..edcd1e835adad7d93d969e6a9c8cb1fe3288456d 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -470,7 +470,7 @@ int utf8_fprintf(FILE *stream, const char *format, ...)
 #else
        typedef char * iconv_ibp;
 #endif
-char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, int *outsz_p)
+char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, size_t *outsz_p)
 {
        size_t outsz, outalloc;
        char *out, *outpos;
@@ -534,9 +534,9 @@ static const char *fallback_encoding(const char *name)
        return name;
 }
 
-char *reencode_string_len(const char *in, int insz,
+char *reencode_string_len(const char *in, size_t insz,
                          const char *out_encoding, const char *in_encoding,
-                         int *outsz)
+                         size_t *outsz)
 {
        iconv_t conv;
        char *out;
diff --git a/utf8.h b/utf8.h
index db73a2d8d374e7570471627693ecddc87d998f10..ce1c2696e069782807354a846f2cfe075e1dfd5c 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -25,14 +25,14 @@ void strbuf_utf8_replace(struct strbuf *sb, int pos, int width,
 
 #ifndef NO_ICONV
 char *reencode_string_iconv(const char *in, size_t insz,
-                           iconv_t conv, int *outsz);
-char *reencode_string_len(const char *in, int insz,
+                           iconv_t conv, size_t *outsz);
+char *reencode_string_len(const char *in, size_t insz,
                          const char *out_encoding,
                          const char *in_encoding,
-                         int *outsz);
+                         size_t *outsz);
 #else
-static inline char *reencode_string_len(const char *a, int b,
-                                       const char *c, const char *d, int *e)
+static inline char *reencode_string_len(const char *a, size_t b,
+                                       const char *c, const char *d, size_t *e)
 { if (e) *e = 0; return NULL; }
 #endif