Skip to content

Commit c7d017d

Browse files
peffgitster
authored andcommitted
reencode_string: use size_t for string lengths
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>
1 parent 77aa03d commit c7d017d

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

convert.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
389389
struct strbuf *buf, const char *enc, int conv_flags)
390390
{
391391
char *dst;
392-
int dst_len;
392+
size_t dst_len;
393393
int die_on_error = conv_flags & CONV_WRITE_OBJECT;
394394

395395
/*
@@ -452,7 +452,7 @@ static int encode_to_git(const char *path, const char *src, size_t src_len,
452452
*/
453453
if (die_on_error && check_roundtrip(enc)) {
454454
char *re_src;
455-
int re_src_len;
455+
size_t re_src_len;
456456

457457
re_src = reencode_string_len(dst, dst_len,
458458
enc, default_encoding,
@@ -480,7 +480,7 @@ static int encode_to_worktree(const char *path, const char *src, size_t src_len,
480480
struct strbuf *buf, const char *enc)
481481
{
482482
char *dst;
483-
int dst_len;
483+
size_t dst_len;
484484

485485
/*
486486
* No encoding is specified or there is nothing to encode.

pretty.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ void format_commit_message(const struct commit *commit,
15381538
}
15391539

15401540
if (output_enc) {
1541-
int outsz;
1541+
size_t outsz;
15421542
char *out = reencode_string_len(sb->buf, sb->len,
15431543
output_enc, utf8, &outsz);
15441544
if (out)

strbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void strbuf_ltrim(struct strbuf *sb)
134134
int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
135135
{
136136
char *out;
137-
int len;
137+
size_t len;
138138

139139
if (same_encoding(from, to))
140140
return 0;

utf8.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int utf8_fprintf(FILE *stream, const char *format, ...)
470470
#else
471471
typedef char * iconv_ibp;
472472
#endif
473-
char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, int *outsz_p)
473+
char *reencode_string_iconv(const char *in, size_t insz, iconv_t conv, size_t *outsz_p)
474474
{
475475
size_t outsz, outalloc;
476476
char *out, *outpos;
@@ -534,9 +534,9 @@ static const char *fallback_encoding(const char *name)
534534
return name;
535535
}
536536

537-
char *reencode_string_len(const char *in, int insz,
537+
char *reencode_string_len(const char *in, size_t insz,
538538
const char *out_encoding, const char *in_encoding,
539-
int *outsz)
539+
size_t *outsz)
540540
{
541541
iconv_t conv;
542542
char *out;

utf8.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ void strbuf_utf8_replace(struct strbuf *sb, int pos, int width,
2525

2626
#ifndef NO_ICONV
2727
char *reencode_string_iconv(const char *in, size_t insz,
28-
iconv_t conv, int *outsz);
29-
char *reencode_string_len(const char *in, int insz,
28+
iconv_t conv, size_t *outsz);
29+
char *reencode_string_len(const char *in, size_t insz,
3030
const char *out_encoding,
3131
const char *in_encoding,
32-
int *outsz);
32+
size_t *outsz);
3333
#else
34-
static inline char *reencode_string_len(const char *a, int b,
35-
const char *c, const char *d, int *e)
34+
static inline char *reencode_string_len(const char *a, size_t b,
35+
const char *c, const char *d, size_t *e)
3636
{ if (e) *e = 0; return NULL; }
3737
#endif
3838

0 commit comments

Comments
 (0)