Skip to content

Commit

Permalink
utf8: change type from int to size_t
Browse files Browse the repository at this point in the history
Since `utf8_strnwidth` & `utf8_strwidth` now returns size_t instead
of int, this patch updates the variable types used to store the
return values of these functions.

Signed-off-by: Mohit Marathe <[email protected]>
  • Loading branch information
mohit-marathe committed Mar 13, 2024
1 parent 2782878 commit 3f36181
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static const char *annotate_opt_usage[] = {
};

static int longest_file;
static int longest_author;
static size_t longest_author;
static int max_orig_digits;
static int max_digits;
static int max_score_digits;
Expand Down Expand Up @@ -529,7 +529,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int
name = ci.author_mail.buf;
else
name = ci.author.buf;
pad = longest_author - utf8_strwidth(name);
pad = cast_size_t_to_int(longest_author - utf8_strwidth(name));
printf(" (%s%*s %10s",
name, pad, "",
format_time(ci.author_time,
Expand Down Expand Up @@ -631,7 +631,7 @@ static void find_alignment(struct blame_scoreboard *sb, int *option)

for (e = sb->ent; e; e = e->next) {
struct blame_origin *suspect = e->suspect;
int num;
size_t num;

if (compute_auto_abbrev)
auto_abbrev = update_auto_abbrev(auto_abbrev, suspect);
Expand Down
2 changes: 1 addition & 1 deletion builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static int calc_maxwidth(struct ref_array *refs, int remote_bonus)
for (i = 0; i < refs->nr; i++) {
struct ref_array_item *it = refs->items[i];
const char *desc = it->refname;
int w;
size_t w;

skip_prefix(it->refname, "refs/heads/", &desc);
skip_prefix(it->refname, "refs/remotes/", &desc);
Expand Down
2 changes: 1 addition & 1 deletion builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ static int refcol_width(const struct ref *ref_map, int compact_format)
max = max * 2 / 3;

for (ref = ref_map; ref; ref = ref->next) {
int rlen, llen = 0, len;
size_t rlen, llen = 0, len;

if (ref->status == REF_STATUS_REJECT_SHALLOW ||
!ref->peer_ref ||
Expand Down
4 changes: 2 additions & 2 deletions builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,8 @@ static void show_worktree_porcelain(struct worktree *wt, int line_terminator)
static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
{
struct strbuf sb = STRBUF_INIT;
int cur_path_len = strlen(wt->path);
int path_adj = cur_path_len - utf8_strwidth(wt->path);
size_t cur_path_len = strlen(wt->path);
int path_adj = cast_size_t_to_int(cur_path_len - utf8_strwidth(wt->path));
const char *reason;

strbuf_addf(&sb, "%-*s ", 1 + path_maxlen + path_adj, wt->path);
Expand Down
2 changes: 1 addition & 1 deletion column.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct column_data {
};

/* return length of 's' in letters, ANSI escapes stripped */
static int item_length(const char *s)
static size_t item_length(const char *s)
{
return utf8_strnwidth(s, strlen(s), 1);
}
Expand Down
8 changes: 5 additions & 3 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,8 @@ void print_stat_summary(FILE *fp, int files,

static void show_stats(struct diffstat_t *data, struct diff_options *options)
{
int i, len, add, del, adds = 0, dels = 0;
int i, add, del, adds = 0, dels = 0;
size_t len = 0;
uintmax_t max_change = 0, max_len = 0;
int total_files = data->nr, count;
int width, name_width, graph_width, number_width = 0, bin_width = 0;
Expand Down Expand Up @@ -2780,7 +2781,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
char *name = file->print_name;
uintmax_t added = file->added;
uintmax_t deleted = file->deleted;
int name_len, padding;
size_t name_len;
int padding;

if (!file->is_interesting && (added + deleted == 0))
continue;
Expand Down Expand Up @@ -2809,7 +2811,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
if (slash)
name = slash;
}
padding = len - utf8_strwidth(name);
padding = cast_size_t_to_int(len - utf8_strwidth(name));
if (padding < 0)
padding = 0;

Expand Down
2 changes: 1 addition & 1 deletion gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void git_setup_gettext(void)
}

/* return the number of columns of string 's' in current locale */
int gettext_width(const char *s)
size_t gettext_width(const char *s)
{
static int is_utf8 = -1;
if (is_utf8 == -1)
Expand Down
2 changes: 1 addition & 1 deletion gettext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef NO_GETTEXT
extern int git_gettext_enabled;
void git_setup_gettext(void);
int gettext_width(const char *s);
size_t gettext_width(const char *s);
#else
#define git_gettext_enabled (0)
static inline void git_setup_gettext(void)
Expand Down
5 changes: 3 additions & 2 deletions pretty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1777,11 +1777,12 @@ static size_t format_and_pad_commit(struct strbuf *sb, /* in UTF-8 */
{
struct strbuf local_sb = STRBUF_INIT;
size_t total_consumed = 0;
int len, padding = c->padding;
int padding = c->padding;
size_t len = c->padding;

if (padding < 0) {
const char *start = strrchr(sb->buf, '\n');
int occupied;
size_t occupied;
if (!start)
start = sb->buf;
occupied = utf8_strnwidth(start, strlen(start), 1);
Expand Down
2 changes: 1 addition & 1 deletion utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ int utf8_fprintf(FILE *stream, const char *format, ...)

columns = fputs(buf.buf, stream);
if (0 <= columns) /* keep the error from the I/O */
columns = utf8_strwidth(buf.buf);
columns = cast_size_t_to_int(utf8_strwidth(buf.buf));
strbuf_release(&buf);
return columns;
}
Expand Down
4 changes: 2 additions & 2 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static int maxwidth(const char *(*label)(int), int minval, int maxval)

for (i = minval; i <= maxval; i++) {
const char *s = label(i);
int len = s ? utf8_strwidth(s) : 0;
size_t len = s ? utf8_strwidth(s) : 0;
if (len > result)
result = len;
}
Expand All @@ -341,7 +341,7 @@ static void wt_longstatus_print_unmerged_data(struct wt_status *s,
static char *padding;
static int label_width;
const char *one, *how;
int len;
size_t len;

if (!padding) {
label_width = maxwidth(wt_status_unmerged_status_string, 1, 7);
Expand Down

0 comments on commit 3f36181

Please sign in to comment.