eliminate signed/unsigned comparison warnings

This partially addresses #3430.
This commit is contained in:
Kurtis Rader 2016-10-09 14:36:08 -07:00
parent 213ef3ee56
commit 851e449347
16 changed files with 70 additions and 83 deletions

View File

@ -2001,7 +2001,7 @@ static int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv)
line = reader_readline(nchars); line = reader_readline(nchars);
proc_pop_interactive(); proc_pop_interactive();
if (line) { if (line) {
if (0 < nchars && nchars < wcslen(line)) { if (0 < nchars && (size_t)nchars < wcslen(line)) {
// Line may be longer than nchars if a keybinding used `commandline -i` // Line may be longer than nchars if a keybinding used `commandline -i`
// note: we're deliberately throwing away the tail of the commandline. // note: we're deliberately throwing away the tail of the commandline.
// It shouldn't be unread because it was produced with `commandline -i`, // It shouldn't be unread because it was produced with `commandline -i`,

View File

@ -118,7 +118,7 @@ show_stackframe(const wchar_t msg_level, int frame_count, int skip_levels) {
if (frame_count < 1) frame_count = 999; if (frame_count < 1) frame_count = 999;
debug_shared(msg_level, L"Backtrace:"); debug_shared(msg_level, L"Backtrace:");
std::vector<wcstring> bt = demangled_backtrace(frame_count, skip_levels + 2); std::vector<wcstring> bt = demangled_backtrace(frame_count, skip_levels + 2);
for (int i = 0; i < bt.size(); i++) { for (int i = 0; (size_t)i < bt.size(); i++) {
debug_shared(msg_level, bt[i]); debug_shared(msg_level, bt[i]);
} }
} }

View File

@ -52,8 +52,8 @@ typedef std::vector<wcstring> wcstring_list_t;
// Use Unicode "noncharacters" for internal characters as much as we can. This // Use Unicode "noncharacters" for internal characters as much as we can. This
// gives us 32 "characters" for internal use that we can guarantee should not // gives us 32 "characters" for internal use that we can guarantee should not
// appear in our input stream. See http://www.unicode.org/faq/private_use.html. // appear in our input stream. See http://www.unicode.org/faq/private_use.html.
#define RESERVED_CHAR_BASE 0xFDD0u #define RESERVED_CHAR_BASE (wchar_t)0xFDD0
#define RESERVED_CHAR_END 0xFDF0u #define RESERVED_CHAR_END (wchar_t)0xFDF0
// Split the available noncharacter values into two ranges to ensure there are // Split the available noncharacter values into two ranges to ensure there are
// no conflicts among the places we use these special characters. // no conflicts among the places we use these special characters.
#define EXPAND_RESERVED_BASE RESERVED_CHAR_BASE #define EXPAND_RESERVED_BASE RESERVED_CHAR_BASE
@ -63,9 +63,9 @@ typedef std::vector<wcstring> wcstring_list_t;
// Make sure the ranges defined above don't exceed the range for noncharacters. // Make sure the ranges defined above don't exceed the range for noncharacters.
// This is to make sure we didn't do something stupid in subdividing the // This is to make sure we didn't do something stupid in subdividing the
// Unicode range for our needs. // Unicode range for our needs.
#if WILDCARD_RESERVED_END > RESERVED_CHAR_END //#if WILDCARD_RESERVED_END > RESERVED_CHAR_END
#error //#error
#endif //#endif
// These are in the Unicode private-use range. We really shouldn't use this // These are in the Unicode private-use range. We really shouldn't use this
// range but have little choice in the matter given how our lexer/parser works. // range but have little choice in the matter given how our lexer/parser works.
@ -79,9 +79,9 @@ typedef std::vector<wcstring> wcstring_list_t;
// Note: We don't use the highest 8 bit range (0xF800 - 0xF8FF) because we know // Note: We don't use the highest 8 bit range (0xF800 - 0xF8FF) because we know
// of at least one use of a codepoint in that range: the Apple symbol (0xF8FF) // of at least one use of a codepoint in that range: the Apple symbol (0xF8FF)
// on Mac OS X. See http://www.unicode.org/faq/private_use.html. // on Mac OS X. See http://www.unicode.org/faq/private_use.html.
#define ENCODE_DIRECT_BASE 0xF600u #define ENCODE_DIRECT_BASE (wchar_t)0xF600
#define ENCODE_DIRECT_END (ENCODE_DIRECT_BASE + 256) #define ENCODE_DIRECT_END (ENCODE_DIRECT_BASE + 256)
#define INPUT_COMMON_BASE 0xF700u #define INPUT_COMMON_BASE (wchar_t)0xF700
#define INPUT_COMMON_END (INPUT_COMMON_BASE + 64) #define INPUT_COMMON_END (INPUT_COMMON_BASE + 64)
// Flags for unescape_string functions. // Flags for unescape_string functions.

View File

@ -826,7 +826,7 @@ var_table_t env_universal_t::read_message_internal(int fd) {
// Walk over it by lines. The contents of an unterminated line will be left in 'line' for // Walk over it by lines. The contents of an unterminated line will be left in 'line' for
// the next iteration. // the next iteration.
size_t line_start = 0; ssize_t line_start = 0;
while (line_start < amt) { while (line_start < amt) {
// Run until we hit a newline. // Run until we hit a newline.
size_t cursor = line_start; size_t cursor = line_start;
@ -1033,7 +1033,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
} }
// Set the size, if it's too small. // Set the size, if it's too small.
if (!errored && size < sizeof(universal_notifier_shmem_t)) { if (!errored && size < (off_t)sizeof(universal_notifier_shmem_t)) {
if (ftruncate(fd, sizeof(universal_notifier_shmem_t)) < 0) { if (ftruncate(fd, sizeof(universal_notifier_shmem_t)) < 0) {
int err = errno; int err = errno;
report_error(err, L"Unable to truncate shared memory object with path '%s'", path); report_error(err, L"Unable to truncate shared memory object with path '%s'", path);
@ -1120,7 +1120,7 @@ class universal_notifier_shmem_poller_t : public universal_notifier_t {
// If it's been less than five seconds since the last change, we poll quickly Otherwise we // If it's been less than five seconds since the last change, we poll quickly Otherwise we
// poll more slowly. Note that a poll is a very cheap shmem read. The bad part about making // poll more slowly. Note that a poll is a very cheap shmem read. The bad part about making
// this high is the process scheduling/wakeups it produces. // this high is the process scheduling/wakeups it produces.
unsigned long usec_per_sec = 1000000; long long usec_per_sec = 1000000;
if (get_time() - last_change_time < 5LL * usec_per_sec) { if (get_time() - last_change_time < 5LL * usec_per_sec) {
return usec_per_sec / 10; // 10 times a second return usec_per_sec / 10; // 10 times a second
} }

View File

@ -301,7 +301,7 @@ int event_get(const event_t &criterion, std::vector<event_t *> *out) {
bool event_is_signal_observed(int sig) { bool event_is_signal_observed(int sig) {
// We are in a signal handler! Don't allocate memory, etc. // We are in a signal handler! Don't allocate memory, etc.
bool result = false; bool result = false;
if (sig >= 0 && sig < sizeof s_observed_signals / sizeof *s_observed_signals) { if (sig >= 0 && (unsigned long)sig < sizeof(s_observed_signals) / sizeof(*s_observed_signals)) {
result = s_observed_signals[sig]; result = s_observed_signals[sig];
} }
return result; return result;

View File

@ -756,13 +756,12 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
for (long i = last_idx - 1; (i >= 0) && is_ok && !empty; i--) { for (long i = last_idx - 1; (i >= 0) && is_ok && !empty; i--) {
const wchar_t c = instr.at(i); const wchar_t c = instr.at(i);
if ((c == VARIABLE_EXPAND) || (c == VARIABLE_EXPAND_SINGLE)) { if ((c == VARIABLE_EXPAND) || (c == VARIABLE_EXPAND_SINGLE)) {
long start_pos = i + 1; size_t start_pos = i + 1;
long stop_pos; size_t stop_pos;
long var_len; long var_len;
int is_single = (c == VARIABLE_EXPAND_SINGLE); int is_single = (c == VARIABLE_EXPAND_SINGLE);
stop_pos = start_pos; stop_pos = start_pos;
while (stop_pos < insize) { while (stop_pos < insize) {
const wchar_t nc = instr.at(stop_pos); const wchar_t nc = instr.at(stop_pos);
if (nc == VARIABLE_EXPAND_EMPTY) { if (nc == VARIABLE_EXPAND_EMPTY) {

View File

@ -562,7 +562,7 @@ static size_t offset_of_next_item_fish_2_0(const char *begin, size_t mmap_length
// leading "- cmd: - cmd: - cmd:". Trim all but one leading "- cmd:". // leading "- cmd: - cmd: - cmd:". Trim all but one leading "- cmd:".
const char *double_cmd = "- cmd: - cmd: "; const char *double_cmd = "- cmd: - cmd: ";
const size_t double_cmd_len = strlen(double_cmd); const size_t double_cmd_len = strlen(double_cmd);
while (a_newline - line_start > double_cmd_len && while ((size_t)(a_newline - line_start) > double_cmd_len &&
!memcmp(line_start, double_cmd, double_cmd_len)) { !memcmp(line_start, double_cmd, double_cmd_len)) {
// Skip over just one of the - cmd. In the end there will be just one left. // Skip over just one of the - cmd. In the end there will be just one left.
line_start += strlen("- cmd: "); line_start += strlen("- cmd: ");
@ -572,8 +572,10 @@ static size_t offset_of_next_item_fish_2_0(const char *begin, size_t mmap_length
// 123456". Ignore those. // 123456". Ignore those.
const char *cmd_when = "- cmd: when:"; const char *cmd_when = "- cmd: when:";
const size_t cmd_when_len = strlen(cmd_when); const size_t cmd_when_len = strlen(cmd_when);
if (a_newline - line_start >= cmd_when_len && !memcmp(line_start, cmd_when, cmd_when_len)) if ((size_t)(a_newline - line_start) >= cmd_when_len &&
!memcmp(line_start, cmd_when, cmd_when_len)) {
continue; continue;
}
// At this point, we know line_start is at the beginning of an item. But maybe we want to // At this point, we know line_start is at the beginning of an item. But maybe we want to
// skip this item because of timestamps. A 0 cutoff means we don't care; if we do care, then // skip this item because of timestamps. A 0 cutoff means we don't care; if we do care, then

View File

@ -124,7 +124,7 @@ static const wchar_t *const name_arr[] = {L"beginning-of-line",
wcstring describe_char(wint_t c) { wcstring describe_char(wint_t c) {
wint_t initial_cmd_char = R_BEGINNING_OF_LINE; wint_t initial_cmd_char = R_BEGINNING_OF_LINE;
size_t name_count = sizeof name_arr / sizeof *name_arr; long name_count = sizeof(name_arr) / sizeof(*name_arr);
if (c >= initial_cmd_char && c < initial_cmd_char + name_count) { if (c >= initial_cmd_char && c < initial_cmd_char + name_count) {
return format_string(L"%02x (%ls)", c, name_arr[c - initial_cmd_char]); return format_string(L"%02x (%ls)", c, name_arr[c - initial_cmd_char]);
} }
@ -535,7 +535,7 @@ static void input_mapping_execute_matching_or_generic(bool allow_commands) {
const wcstring bind_mode = input_get_bind_mode(); const wcstring bind_mode = input_get_bind_mode();
for (int i = 0; i < mapping_list.size(); i++) { for (size_t i = 0; i < mapping_list.size(); i++) {
const input_mapping_t &m = mapping_list.at(i); const input_mapping_t &m = mapping_list.at(i);
// debug(0, L"trying mapping (%ls,%ls,%ls)\n", escape(m.seq.c_str(), ESCAPE_ALL).c_str(), // debug(0, L"trying mapping (%ls,%ls,%ls)\n", escape(m.seq.c_str(), ESCAPE_ALL).c_str(),

View File

@ -49,7 +49,7 @@ void output_set_writer(int (*writer)(char)) {
int (*output_get_writer())(char) { return out; } int (*output_get_writer())(char) { return out; }
/// Returns true if we think tparm can handle outputting a color index /// Returns true if we think tparm can handle outputting a color index
static bool term_supports_color_natively(unsigned int c) { return max_colors >= (c + 1); } static bool term_supports_color_natively(unsigned int c) { return (unsigned)max_colors >= c + 1; }
color_support_t output_get_color_support(void) { return color_support; } color_support_t output_get_color_support(void) { return color_support; }

View File

@ -50,8 +50,8 @@ static size_t divide_round_up(size_t numer, size_t denom) {
void pager_t::recalc_min_widths(comp_info_list_t *lst) const { void pager_t::recalc_min_widths(comp_info_list_t *lst) const {
for (size_t i = 0; i < lst->size(); i++) { for (size_t i = 0; i < lst->size(); i++) {
comp_t *c = &lst->at(i); comp_t *c = &lst->at(i);
c->min_width = mini(c->desc_width, maxi(0, available_term_width / 3 - 2)) + c->min_width = mini(c->desc_width, maxi((size_t)0, available_term_width / 3 - 2)) +
mini(c->desc_width, maxi(0, available_term_width / 5 - 4)) + 4; mini(c->desc_width, maxi((size_t)0, available_term_width / 5 - 4)) + 4;
} }
} }
@ -84,14 +84,13 @@ static int print_max(const wcstring &str, highlight_spec_t color, int max, bool
/// Print the specified item using at the specified amount of space. /// Print the specified item using at the specified amount of space.
line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, size_t row, line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, size_t row,
size_t column, int width, bool secondary, bool selected, size_t column, size_t width, bool secondary, bool selected,
page_rendering_t *rendering) const { page_rendering_t *rendering) const {
int comp_width = 0, desc_width = 0; size_t comp_width = 0, desc_width = 0;
int written = 0; size_t written = 0;
line_t line_data; line_t line_data;
if (c->pref_width <= width) { if (c->pref_width <= (size_t)width) {
// The entry fits, we give it as much space as it wants. // The entry fits, we give it as much space as it wants.
comp_width = c->comp_width; comp_width = c->comp_width;
desc_width = c->desc_width; desc_width = c->desc_width;
@ -379,12 +378,12 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
bool print = false; bool print = false;
// Compute the effective term width and term height, accounting for disclosure. // Compute the effective term width and term height, accounting for disclosure.
int term_width = this->available_term_width; size_t term_width = this->available_term_width;
int term_height = size_t term_height =
this->available_term_height - 1 - this->available_term_height - 1 -
(search_field_shown ? 1 : 0); // we always subtract 1 to make room for a comment row (search_field_shown ? 1 : 0); // we always subtract 1 to make room for a comment row
if (!this->fully_disclosed) { if (!this->fully_disclosed) {
term_height = mini(term_height, PAGER_UNDISCLOSED_MAX_ROWS); term_height = mini(term_height, (size_t)PAGER_UNDISCLOSED_MAX_ROWS);
} }
size_t row_count = divide_round_up(lst.size(), cols); size_t row_count = divide_round_up(lst.size(), cols);
@ -404,15 +403,15 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
rendering->remaining_to_disclose = 0; rendering->remaining_to_disclose = 0;
} }
int pref_tot_width = 0; size_t pref_tot_width = 0;
int min_tot_width = 0; size_t min_tot_width = 0;
// Skip completions on tiny terminals. // Skip completions on tiny terminals.
if (term_width < PAGER_MIN_WIDTH) return true; if (term_width < PAGER_MIN_WIDTH) return true;
// Calculate how wide the list would be. // Calculate how wide the list would be.
for (long col = 0; col < cols; col++) { for (size_t col = 0; col < cols; col++) {
for (long row = 0; row < row_count; row++) { for (size_t row = 0; row < row_count; row++) {
int pref, min; int pref, min;
const comp_t *c; const comp_t *c;
if (lst.size() <= col * row_count + row) continue; if (lst.size() <= col * row_count + row) continue;
@ -526,7 +525,7 @@ page_rendering_t pager_t::render() const {
rendering.search_field_shown = this->search_field_shown; rendering.search_field_shown = this->search_field_shown;
rendering.search_field_line = this->search_field_line; rendering.search_field_line = this->search_field_line;
for (int cols = PAGER_MAX_COLS; cols > 0; cols--) { for (size_t cols = PAGER_MAX_COLS; cols > 0; cols--) {
// Initially empty rendering. // Initially empty rendering.
rendering.screen_data.resize(0); rendering.screen_data.resize(0);
@ -641,7 +640,7 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
// Cardinal directions. We have a completion index; we wish to compute its row and column. // Cardinal directions. We have a completion index; we wish to compute its row and column.
size_t current_row = this->get_selected_row(rendering); size_t current_row = this->get_selected_row(rendering);
size_t current_col = this->get_selected_column(rendering); size_t current_col = this->get_selected_column(rendering);
size_t page_height = maxi(rendering.term_height - 1, 1); size_t page_height = maxi(rendering.term_height - 1, (size_t)1);
switch (direction) { switch (direction) {
case direction_page_north: { case direction_page_north: {

View File

@ -17,8 +17,8 @@
/// Represents rendering from the pager. /// Represents rendering from the pager.
class page_rendering_t { class page_rendering_t {
public: public:
int term_width; size_t term_width;
int term_height; size_t term_height;
size_t rows; size_t rows;
size_t cols; size_t cols;
size_t row_start; size_t row_start;
@ -47,8 +47,8 @@ page_rendering_t render_completions(const completion_list_t &raw_completions,
const wcstring &prefix); const wcstring &prefix);
class pager_t { class pager_t {
int available_term_width; size_t available_term_width;
int available_term_height; size_t available_term_height;
size_t selected_completion_idx; size_t selected_completion_idx;
size_t suggested_row_start; size_t suggested_row_start;
@ -73,13 +73,13 @@ class pager_t {
/// The representative completion. /// The representative completion.
completion_t representative; completion_t representative;
/// On-screen width of the completion string. /// On-screen width of the completion string.
int comp_width; size_t comp_width;
/// On-screen width of the description information. /// On-screen width of the description information.
int desc_width; size_t desc_width;
/// Preferred total width. /// Preferred total width.
int pref_width; size_t pref_width;
/// Minimum acceptable width. /// Minimum acceptable width.
int min_width; size_t min_width;
comp_t() comp_t()
: comp(), : comp(),
@ -114,7 +114,7 @@ class pager_t {
const wcstring &prefix, const comp_info_list_t &lst, const wcstring &prefix, const comp_info_list_t &lst,
page_rendering_t *rendering) const; page_rendering_t *rendering) const;
line_t completion_print_item(const wcstring &prefix, const comp_t *c, size_t row, size_t column, line_t completion_print_item(const wcstring &prefix, const comp_t *c, size_t row, size_t column,
int width, bool secondary, bool selected, size_t width, bool secondary, bool selected,
page_rendering_t *rendering) const; page_rendering_t *rendering) const;
public: public:

View File

@ -67,16 +67,11 @@ size_t parse_util_get_offset_from_line(const wcstring &str, int line) {
size_t i; size_t i;
int count = 0; int count = 0;
if (line < 0) { if (line < 0) return (size_t)-1;
return (size_t)-1;
}
if (line == 0) return 0; if (line == 0) return 0;
for (i = 0;; i++) { for (i = 0;; i++) {
if (!buff[i]) { if (!buff[i]) return (size_t)-1;
return -1;
}
if (buff[i] == L'\n') { if (buff[i] == L'\n') {
count++; count++;
@ -91,25 +86,18 @@ size_t parse_util_get_offset(const wcstring &str, int line, long line_offset) {
const wchar_t *buff = str.c_str(); const wchar_t *buff = str.c_str();
size_t off = parse_util_get_offset_from_line(buff, line); size_t off = parse_util_get_offset_from_line(buff, line);
size_t off2 = parse_util_get_offset_from_line(buff, line + 1); size_t off2 = parse_util_get_offset_from_line(buff, line + 1);
long line_offset2 = line_offset;
if (off == (size_t)(-1)) { if (off == (size_t)-1) return (size_t)-1;
return -1;
if (off2 == (size_t)-1) off2 = wcslen(buff) + 1;
if (line_offset < 0) line_offset = 0;
if ((size_t)line_offset >= off2 - off - 1) {
line_offset = off2 - off - 1;
} }
if (off2 == (size_t)(-1)) { return off + line_offset;
off2 = wcslen(buff) + 1;
}
if (line_offset2 < 0) {
line_offset2 = 0;
}
if (line_offset2 >= off2 - off - 1) {
line_offset2 = off2 - off - 1;
}
return off + line_offset2;
} }
static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin, wchar_t **end, static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin, wchar_t **end,
@ -305,7 +293,7 @@ static void job_or_process_extent(const wchar_t *buff, size_t cursor_pos, const
return; return;
} }
assert(cursor_pos >= (begin - buff)); assert(cursor_pos >= (size_t)(begin - buff));
const size_t pos = cursor_pos - (begin - buff); const size_t pos = cursor_pos - (begin - buff);
if (a) *a = begin; if (a) *a = begin;
@ -369,7 +357,7 @@ void parse_util_token_extent(const wchar_t *buff, size_t cursor_pos, const wchar
} }
// pos is equivalent to cursor_pos within the range of the command substitution {begin, end}. // pos is equivalent to cursor_pos within the range of the command substitution {begin, end}.
long offset_within_cmdsubst = cursor_pos - (cmdsubst_begin - buff); size_t offset_within_cmdsubst = cursor_pos - (cmdsubst_begin - buff);
a = cmdsubst_begin + offset_within_cmdsubst; a = cmdsubst_begin + offset_within_cmdsubst;
b = a; b = a;

View File

@ -2743,7 +2743,7 @@ const wchar_t *reader_readline(int nchars) {
if (data->search_mode) { if (data->search_mode) {
data->search_mode = NO_SEARCH; data->search_mode = NO_SEARCH;
if (data->token_history_pos == -1) { if (data->token_history_pos == (size_t)-1) {
// history_reset(); // history_reset();
data->history_search.go_to_end(); data->history_search.go_to_end();
reader_set_buffer(data->search_buff, data->search_buff.size()); reader_set_buffer(data->search_buff, data->search_buff.size());

View File

@ -388,13 +388,12 @@ static void s_desired_append_char(screen_t *s, wchar_t b, int c, int indent, siz
int line_no = s->desired.cursor.y; int line_no = s->desired.cursor.y;
if (b == L'\n') { if (b == L'\n') {
int i;
// Current line is definitely hard wrapped. // Current line is definitely hard wrapped.
s->desired.create_line(s->desired.line_count()); s->desired.create_line(s->desired.line_count());
s->desired.line(s->desired.cursor.y).is_soft_wrapped = false; s->desired.line(s->desired.cursor.y).is_soft_wrapped = false;
s->desired.cursor.y++; s->desired.cursor.y++;
s->desired.cursor.x = 0; s->desired.cursor.x = 0;
for (i = 0; i < prompt_width + indent * INDENT_STEP; i++) { for (size_t i = 0; i < prompt_width + indent * INDENT_STEP; i++) {
s_desired_append_char(s, L' ', 0, indent, prompt_width); s_desired_append_char(s, L' ', 0, indent, prompt_width);
} }
} else if (b == L'\r') { } else if (b == L'\r') {
@ -732,7 +731,7 @@ static void s_update(screen_t *scr, const wchar_t *left_prompt, const wchar_t *r
// avoid repeatedly outputting it. // avoid repeatedly outputting it.
const size_t shared_prefix = line_shared_prefix(o_line, s_line); const size_t shared_prefix = line_shared_prefix(o_line, s_line);
if (shared_prefix > 0) { if (shared_prefix > 0) {
int prefix_width = fish_wcswidth(&o_line.text.at(0), shared_prefix); size_t prefix_width = fish_wcswidth(&o_line.text.at(0), shared_prefix);
if (prefix_width > skip_remaining) skip_remaining = prefix_width; if (prefix_width > skip_remaining) skip_remaining = prefix_width;
} }
@ -754,7 +753,7 @@ static void s_update(screen_t *scr, const wchar_t *left_prompt, const wchar_t *r
// Skip over skip_remaining width worth of characters. // Skip over skip_remaining width worth of characters.
size_t j = 0; size_t j = 0;
for (; j < o_line.size(); j++) { for (; j < o_line.size(); j++) {
int width = fish_wcwidth_min_0(o_line.char_at(j)); size_t width = fish_wcwidth_min_0(o_line.char_at(j));
if (skip_remaining < width) break; if (skip_remaining < width) break;
skip_remaining -= width; skip_remaining -= width;
current_width += width; current_width += width;
@ -772,7 +771,8 @@ static void s_update(screen_t *scr, const wchar_t *left_prompt, const wchar_t *r
// the screen after we output into the last column, it can erase the last character due // the screen after we output into the last column, it can erase the last character due
// to the sticky right cursor. If we clear the screen too early, we can defeat soft // to the sticky right cursor. If we clear the screen too early, we can defeat soft
// wrapping. // wrapping.
if (j + 1 == screen_width && should_clear_screen_this_line && !has_cleared_screen) { if (j + 1 == (size_t)screen_width && should_clear_screen_this_line &&
!has_cleared_screen) {
s_move(scr, &output, current_width, (int)i); s_move(scr, &output, current_width, (int)i);
s_write_mbs(&output, clr_eos); s_write_mbs(&output, clr_eos);
has_cleared_screen = true; has_cleared_screen = true;

View File

@ -31,7 +31,7 @@
// We can tweak the following typedef to allow us to simulate Windows-style 16 bit wchar's on Unix. // We can tweak the following typedef to allow us to simulate Windows-style 16 bit wchar's on Unix.
typedef wchar_t utf8_wchar_t; typedef wchar_t utf8_wchar_t;
#define UTF8_WCHAR_MAX ((size_t)std::numeric_limits<utf8_wchar_t>::max()) #define UTF8_WCHAR_MAX (wchar_t)std::numeric_limits<utf8_wchar_t>::max()
typedef std::basic_string<utf8_wchar_t> utf8_wstring_t; typedef std::basic_string<utf8_wchar_t> utf8_wstring_t;
@ -197,7 +197,7 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
} }
// Does the sequence header tell us truth about length? // Does the sequence header tell us truth about length?
if (lim - p <= n - 1) { if ((size_t)(lim - p) <= n - 1) {
if ((flags & UTF8_IGNORE_ERROR) == 0) return 0; if ((flags & UTF8_IGNORE_ERROR) == 0) return 0;
n = 1; n = 1;
continue; // skip continue; // skip
@ -238,7 +238,7 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
if (skip) { if (skip) {
total--; total--;
} else if (out_val > UTF8_WCHAR_MAX) { } else if (out_val > (uint32_t)UTF8_WCHAR_MAX) {
// wchar_t is UCS-2, but the UTF-8 specified an astral character. // wchar_t is UCS-2, but the UTF-8 specified an astral character.
return 0; return 0;
} else { } else {
@ -304,8 +304,7 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char
total += n; total += n;
if (out == NULL) continue; if (out == NULL) continue;
if (size_t(lim - p) <= n - 1) return 0; // no space left
if (lim - p <= n - 1) return 0; // no space left
// Extract the wchar_t as big-endian. If wchar_t is UCS-16, the first two bytes will be 0. // Extract the wchar_t as big-endian. If wchar_t is UCS-16, the first two bytes will be 0.
unsigned char oc[4]; unsigned char oc[4];

View File

@ -348,7 +348,7 @@ wchar_t *wrealpath(const wcstring &pathname, wchar_t *resolved_path) {
if (narrow_res) { if (narrow_res) {
real_path.append(narrow_res); real_path.append(narrow_res);
} else { } else {
ssize_t pathsep_idx = narrow_path.rfind('/'); size_t pathsep_idx = narrow_path.rfind('/');
if (pathsep_idx == 0) { if (pathsep_idx == 0) {
// If the only pathsep is the first character then it's an absolute path with a // If the only pathsep is the first character then it's an absolute path with a
// single path component and thus doesn't need conversion. // single path component and thus doesn't need conversion.