[clang-tidy] Convert C casts to C++ ones

Found with google-readability-casting

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-11-18 17:08:16 -08:00 committed by ridiculousfish
parent 7f62e30731
commit 0dfa7421f3
38 changed files with 249 additions and 219 deletions

View file

@ -129,7 +129,7 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
const wchar_t *current_buffer = 0;
// What the commandline builtin considers to be the current cursor position.
size_t current_cursor_pos = (size_t)(-1);
size_t current_cursor_pos = static_cast<size_t>(-1);
wchar_t *cmd = argv[0];
int buffer_part = 0;
@ -368,10 +368,12 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
}
current_buffer = reader_get_buffer();
new_pos = std::max(0L, std::min(new_pos, (long)std::wcslen(current_buffer)));
reader_set_buffer(current_buffer, (size_t)new_pos);
new_pos =
std::max(0L, std::min(new_pos, static_cast<long>(std::wcslen(current_buffer))));
reader_set_buffer(current_buffer, static_cast<size_t>(new_pos));
} else {
streams.out.append_format(L"%lu\n", (unsigned long)reader_get_cursor_pos());
streams.out.append_format(L"%lu\n",
static_cast<unsigned long>(reader_get_cursor_pos()));
}
return STATUS_CMD_OK;
}
@ -379,7 +381,8 @@ int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
if (line_mode) {
size_t pos = reader_get_cursor_pos();
const wchar_t *buff = reader_get_buffer();
streams.out.append_format(L"%lu\n", (unsigned long)parse_util_lineno(buff, pos));
streams.out.append_format(L"%lu\n",
static_cast<unsigned long>(parse_util_lineno(buff, pos)));
return STATUS_CMD_OK;
}

View file

@ -30,7 +30,7 @@ static const enum_map<hist_cmd_t> hist_enum_map[] = {
struct history_cmd_opts_t {
hist_cmd_t hist_cmd = HIST_UNDEF;
history_search_type_t search_type = (history_search_type_t)-1;
history_search_type_t search_type = static_cast<history_search_type_t>(-1);
const wchar_t *show_time_format = NULL;
size_t max_items = SIZE_MAX;
bool print_help = false;

View file

@ -39,7 +39,7 @@ static int cpu_use(const job_t *j) {
double t2 = 1000000.0 * t.tv_sec + t.tv_usec;
// std::fwprintf( stderr, L"t1 %f t2 %f p1 %d p2 %d\n", t1, t2, jiffies, p->last_jiffies );
u += ((double)(jiffies - p->last_jiffies)) / (t2 - t1);
u += (static_cast<double>(jiffies - p->last_jiffies)) / (t2 - t1);
}
return u * 1000000;
}

View file

@ -710,7 +710,7 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch
wchar_t conversion = *f;
if (conversion > 0xFF || !ok[conversion]) {
this->fatal_error(_(L"%.*ls: invalid conversion specification"),
(int)(f + 1 - direc_start), direc_start);
static_cast<int>(f + 1 - direc_start), direc_start);
return 0;
}

View file

@ -220,7 +220,7 @@ static int read_interactive(parser_t &parser, wcstring &buff, int nchars, bool s
interactive.restore();
if (mline) {
buff = mline.acquire();
if (nchars > 0 && (size_t)nchars < buff.size()) {
if (nchars > 0 && static_cast<size_t>(nchars) < buff.size()) {
// Line may be longer than nchars if a keybinding used `commandline -i`
// note: we're deliberately throwing away the tail of the commandline.
// It shouldn't be unread because it was produced with `commandline -i`,
@ -307,13 +307,13 @@ static int read_one_char_at_a_time(int fd, wcstring &buff, int nchars, bool spli
nbytes++;
if (MB_CUR_MAX == 1) {
res = (unsigned char)b;
res = static_cast<unsigned char>(b);
finished = true;
} else {
size_t sz = std::mbrtowc(&res, &b, 1, &state);
if (sz == (size_t)-1) {
if (sz == static_cast<size_t>(-1)) {
std::memset(&state, 0, sizeof(state));
} else if (sz != (size_t)-2) {
} else if (sz != static_cast<size_t>(-2)) {
finished = true;
}
}
@ -328,7 +328,7 @@ static int read_one_char_at_a_time(int fd, wcstring &buff, int nchars, bool spli
if (split_null && res == L'\0') break;
buff.push_back(res);
if (nchars > 0 && (size_t)nchars <= buff.size()) {
if (nchars > 0 && static_cast<size_t>(nchars) <= buff.size()) {
break;
}
}

View file

@ -382,7 +382,7 @@ static int parse_index(std::vector<long> &indexes, wchar_t *src, int scope, io_s
streams.err.append_format(_(L"%ls: Invalid index starting at '%ls'\n"), L"set", src);
return -1;
}
p = (wchar_t *)end;
p = const_cast<wchar_t *>(end);
// Convert negative index to a positive index.
if (l_ind < 0) l_ind = var.size() + l_ind + 1;
@ -393,7 +393,7 @@ static int parse_index(std::vector<long> &indexes, wchar_t *src, int scope, io_s
if (errno > 0) { // ignore errno == -1 meaning the int did not end with a '\0'
return -1;
}
p = (wchar_t *)end;
p = const_cast<wchar_t *>(end);
// Convert negative index to a positive index.
if (l_ind2 < 0) l_ind2 = var.size() + l_ind2 + 1;
@ -423,7 +423,7 @@ static int update_values(wcstring_list_t &list, std::vector<long> &indexes,
if (ind < 0) {
return 1;
}
if ((size_t)ind >= list.size()) {
if (static_cast<size_t>(ind) >= list.size()) {
list.resize(ind + 1);
}
@ -444,7 +444,7 @@ static void erase_values(wcstring_list_t &list, const std::vector<long> &indexes
decltype(indexes_set)::const_reverse_iterator iter;
for (iter = indexes_set.rbegin(); iter != indexes_set.rend(); ++iter) {
long val = *iter;
if (val > 0 && (size_t)val <= list.size()) {
if (val > 0 && static_cast<size_t>(val) <= list.size()) {
// One-based indexing!
list.erase(list.begin() + val - 1);
}
@ -535,7 +535,7 @@ static int builtin_set_query(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
if (dest_str) dest_str->to_list(result);
for (auto idx : indexes) {
if (idx < 1 || (size_t)idx > result.size()) retval++;
if (idx < 1 || static_cast<size_t>(idx) > result.size()) retval++;
}
} else {
if (!parser.vars().get(arg, scope)) retval++;

View file

@ -676,7 +676,8 @@ class wildcard_matcher_t : public string_matcher_t {
static wcstring pcre2_strerror(int err_code) {
wchar_t buf[128];
pcre2_get_error_message(err_code, (PCRE2_UCHAR *)buf, sizeof(buf) / sizeof(wchar_t));
pcre2_get_error_message(err_code, reinterpret_cast<PCRE2_UCHAR *>(buf),
sizeof(buf) / sizeof(wchar_t));
return buf;
}
@ -762,8 +763,7 @@ class pcre2_matcher_t : public string_matcher_t {
if (begin != PCRE2_UNSET && end != PCRE2_UNSET && !opts.quiet) {
if (opts.index) {
streams.out.append_format(L"%lu %lu", (unsigned long)(begin + 1),
(unsigned long)(end - begin));
streams.out.append_format(L"%lu %lu", (begin + 1), (end - begin));
} else if (end > begin) {
// May have end < begin if \K is used.
streams.out.append(arg.substr(begin, end - begin));
@ -999,7 +999,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) {
(opts.all ? PCRE2_SUBSTITUTE_GLOBAL : 0);
size_t arglen = arg.length();
PCRE2_SIZE bufsize = (arglen == 0) ? 16 : 2 * arglen;
wchar_t *output = (wchar_t *)malloc(sizeof(wchar_t) * bufsize);
wchar_t *output = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * bufsize));
int pcre2_rc;
PCRE2_SIZE outlen = bufsize;
@ -1012,13 +1012,14 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) {
options, regex.match,
0, // match context
PCRE2_SPTR(replacement->c_str()), replacement->length(),
(PCRE2_UCHAR *)output, &outlen);
reinterpret_cast<PCRE2_UCHAR *>(output), &outlen);
if (pcre2_rc != PCRE2_ERROR_NOMEMORY || bufsize >= outlen) {
done = true;
} else {
bufsize = outlen;
wchar_t *new_output = (wchar_t *)realloc(output, sizeof(wchar_t) * bufsize);
wchar_t *new_output =
static_cast<wchar_t *>(realloc(output, sizeof(wchar_t) * bufsize));
if (new_output) output = new_output;
}
}
@ -1195,7 +1196,8 @@ static int string_repeat(parser_t &parser, io_streams_t &streams, int argc, wcha
arg_iterator_t aiter(argv, optind, streams);
if (const wcstring *word = aiter.nextstr()) {
const bool limit_repeat =
(opts.max > 0 && word->length() * opts.count > (size_t)opts.max) || !opts.count;
(opts.max > 0 && word->length() * opts.count > static_cast<size_t>(opts.max)) ||
!opts.count;
const wcstring repeated =
limit_repeat ? wcsrepeat_until(*word, opts.max) : wcsrepeat(*word, opts.count);
is_empty = repeated.empty();

View file

@ -543,7 +543,8 @@ unique_ptr<expression> test_parser::parse_args(const wcstring_list_t &args, wcst
assert(args.size() > 1);
test_parser parser(args);
unique_ptr<expression> result = parser.parse_expression(0, (unsigned int)args.size());
unique_ptr<expression> result =
parser.parse_expression(0, static_cast<unsigned int>(args.size()));
// Handle errors.
// For now we only show the first error.
@ -561,7 +562,8 @@ unique_ptr<expression> test_parser::parse_args(const wcstring_list_t &args, wcst
if (result->range.end < args.size()) {
if (err.empty()) {
append_format(err, L"%ls: unexpected argument at index %lu: '%ls'\n", program_name,
(unsigned long)result->range.end, args.at(result->range.end).c_str());
static_cast<unsigned long>(result->range.end),
args.at(result->range.end).c_str());
}
result.reset(NULL);
}

View file

@ -88,15 +88,15 @@ static int parse_hex_digit(wchar_t x) {
}
static unsigned long squared_difference(long p1, long p2) {
unsigned long diff = (unsigned long)labs(p1 - p2);
unsigned long diff = static_cast<unsigned long>(labs(p1 - p2));
return diff * diff;
}
static unsigned char convert_color(const unsigned char rgb[3], const uint32_t *colors,
size_t color_count) {
long r = rgb[0], g = rgb[1], b = rgb[2];
unsigned long best_distance = (unsigned long)-1;
unsigned char best_index = (unsigned char)-1;
unsigned long best_distance = static_cast<unsigned long>(-1);
unsigned char best_index = static_cast<unsigned char>(-1);
for (unsigned char idx = 0; idx < color_count; idx++) {
uint32_t color = colors[idx];
long test_r = (color >> 16) & 0xFF, test_g = (color >> 8) & 0xFF,
@ -294,7 +294,7 @@ unsigned char rgb_color_t::to_name_index() const {
assert(type == type_named || type == type_rgb);
if (type == type_named) return data.name_idx;
if (type == type_rgb) return term16_color_for_rgb(data.color.rgb);
return (unsigned char)-1; // this is an error
return static_cast<unsigned char>(-1); // this is an error
}
void rgb_color_t::parse(const wcstring &str) {
@ -320,7 +320,7 @@ wcstring rgb_color_t::description() const {
return L"none";
}
case type_named: {
return format_string(L"named(%d: %ls)", (int)data.name_idx,
return format_string(L"named(%d: %ls)", static_cast<int>(data.name_idx),
name_for_color_idx(data.name_idx));
}
case type_rgb: {

View file

@ -222,7 +222,7 @@ bool is_windows_subsystem_for_linux() {
demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);
swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s + %td", i - skip_levels,
status == 0 ? demangled : info.dli_sname == 0 ? symbols[i] : info.dli_sname,
(char *)callstack[i] - (char *)info.dli_saddr);
static_cast<char *>(callstack[i]) - static_cast<char *>(info.dli_saddr));
free(demangled);
} else {
swprintf(text, sizeof(text) / sizeof(wchar_t), L"%-3d %s", i - skip_levels, symbols[i]);
@ -272,7 +272,7 @@ int fgetws2(wcstring *s, FILE *f) {
}
default: {
i++;
s->push_back((wchar_t)c);
s->push_back(static_cast<wchar_t>(c));
break;
}
}
@ -296,7 +296,7 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
if (MB_CUR_MAX == 1) {
// Single-byte locale, all values are legal.
while (in_pos < in_len) {
result.push_back((unsigned char)in[in_pos]);
result.push_back(static_cast<unsigned char>(in[in_pos]));
in_pos++;
}
return result;
@ -325,10 +325,10 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
use_encode_direct = true;
} else if (wc == INTERNAL_SEPARATOR) {
use_encode_direct = true;
} else if (ret == (size_t)-2) {
} else if (ret == static_cast<size_t>(-2)) {
// Incomplete sequence.
use_encode_direct = true;
} else if (ret == (size_t)-1) {
} else if (ret == static_cast<size_t>(-1)) {
// Invalid data.
use_encode_direct = true;
} else if (ret > in_len - in_pos) {
@ -343,7 +343,7 @@ static wcstring str2wcs_internal(const char *in, const size_t in_len) {
}
if (use_encode_direct) {
wc = ENCODE_DIRECT_BASE + (unsigned char)in[in_pos];
wc = ENCODE_DIRECT_BASE + static_cast<unsigned char>(in[in_pos]);
result.push_back(wc);
in_pos++;
std::memset(&state, 0, sizeof state);
@ -390,7 +390,7 @@ char *wcs2str(const wchar_t *in, size_t len) {
}
// Here we probably allocate a buffer probably much larger than necessary.
char *out = (char *)malloc(MAX_UTF8_BYTES * len + 1);
char *out = static_cast<char *>(malloc(MAX_UTF8_BYTES * len + 1));
assert(out);
// Instead of returning the return value of wcs2str_internal, return `out` directly.
// This eliminates false warnings in coverity about resource leaks.
@ -425,7 +425,7 @@ std::string wcs2string(const wcstring &input) {
} else {
std::memset(converted, 0, sizeof converted);
size_t len = std::wcrtomb(converted, wc, &state);
if (len == (size_t)-1) {
if (len == static_cast<size_t>(-1)) {
FLOGF(char_encoding, L"Wide character U+%4X has no narrow representation", wc);
std::memset(&state, 0, sizeof(state));
} else {
@ -459,11 +459,11 @@ static char *wcs2str_internal(const wchar_t *in, char *out) {
if (in[in_pos] & ~0xFF) {
out[out_pos++] = '?';
} else {
out[out_pos++] = (unsigned char)in[in_pos];
out[out_pos++] = static_cast<unsigned char>(in[in_pos]);
}
} else {
size_t len = std::wcrtomb(&out[out_pos], in[in_pos], &state);
if (len == (size_t)-1) {
if (len == static_cast<size_t>(-1)) {
FLOGF(char_encoding, L"Wide character U+%4X has no narrow representation",
in[in_pos]);
std::memset(&state, 0, sizeof(state));
@ -483,7 +483,7 @@ static bool can_be_encoded(wchar_t wc) {
char converted[MB_LEN_MAX];
mbstate_t state = {};
return std::wcrtomb(converted, wc, &state) != (size_t)-1;
return std::wcrtomb(converted, wc, &state) != static_cast<size_t>(-1);
}
wcstring format_string(const wchar_t *format, ...) {
@ -520,7 +520,7 @@ void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig) {
buff[0] = '\0';
break;
}
buff = (wchar_t *)realloc((buff == static_buff ? NULL : buff), size);
buff = static_cast<wchar_t *>(realloc((buff == static_buff ? NULL : buff), size));
assert(buff != NULL);
}
@ -566,7 +566,7 @@ wchar_t *quote_end(const wchar_t *pos) {
if (!*pos) return 0;
} else {
if (*pos == c) {
return (wchar_t *)pos;
return const_cast<wchar_t *>(pos);
}
}
}
@ -613,7 +613,7 @@ long read_blocked(int fd, void *buf, size_t count) {
long bytes_read = 0;
while (count) {
ssize_t res = read(fd, (char *)buf + bytes_read, count);
ssize_t res = read(fd, static_cast<char *>(buf) + bytes_read, count);
if (res == 0) {
break;
} else if (res == -1) {
@ -640,10 +640,10 @@ ssize_t write_loop(int fd, const char *buff, size_t count) {
return -1;
}
} else {
out_cum += (size_t)out;
out_cum += static_cast<size_t>(out);
}
}
return (ssize_t)out_cum;
return static_cast<ssize_t>(out_cum);
}
ssize_t read_loop(int fd, void *buff, size_t count) {
@ -664,11 +664,12 @@ bool should_suppress_stderr_for_tests() {
static void debug_shared(const wchar_t level, const wcstring &msg) {
pid_t current_pid;
if (!is_forked_child()) {
std::fwprintf(stderr, L"<%lc> %ls: %ls\n", (unsigned long)level, program_name, msg.c_str());
std::fwprintf(stderr, L"<%lc> %ls: %ls\n", static_cast<unsigned long>(level), program_name,
msg.c_str());
} else {
current_pid = getpid();
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", (unsigned long)level, program_name,
current_pid, msg.c_str());
std::fwprintf(stderr, L"<%lc> %ls: %d: %ls\n", static_cast<unsigned long>(level),
program_name, current_pid, msg.c_str());
}
}
@ -874,11 +875,11 @@ static void escape_string_url(const wcstring &in, wcstring &out) {
const std::string narrow = wcs2string(in);
for (auto &c1 : narrow) {
// This silliness is so we get the correct result whether chars are signed or unsigned.
unsigned int c2 = (unsigned int)c1 & 0xFF;
unsigned int c2 = static_cast<unsigned int>(c1) & 0xFF;
if (!(c2 & 0x80) &&
(isalnum(c2) || c2 == '/' || c2 == '.' || c2 == '~' || c2 == '-' || c2 == '_')) {
// The above characters don't need to be encoded.
out.push_back((wchar_t)c2);
out.push_back(static_cast<wchar_t>(c2));
} else {
// All other chars need to have their UTF-8 representation encoded in hex.
wchar_t buf[4];
@ -926,14 +927,14 @@ static void escape_string_var(const wcstring &in, wcstring &out) {
const std::string narrow = wcs2string(in);
for (auto c1 : narrow) {
// This silliness is so we get the correct result whether chars are signed or unsigned.
unsigned int c2 = (unsigned int)c1 & 0xFF;
unsigned int c2 = static_cast<unsigned int>(c1) & 0xFF;
if (!(c2 & 0x80) && isalnum(c2) && (!prev_was_hex_encoded || !is_hex_digit(c2))) {
// ASCII alphanumerics don't need to be encoded.
if (prev_was_hex_encoded) {
out.push_back(L'_');
prev_was_hex_encoded = false;
}
out.push_back((wchar_t)c2);
out.push_back(static_cast<wchar_t>(c2));
} else if (c2 == '_') {
// Underscores are encoded by doubling them.
out.append(L"__");
@ -1333,7 +1334,7 @@ maybe_t<size_t> read_unquoted_escape(const wchar_t *input, wcstring *result, boo
max_val = WCHAR_MAX;
// Don't exceed the largest Unicode code point - see #1107.
if (0x10FFFF < max_val) max_val = (wchar_t)0x10FFFF;
if (0x10FFFF < max_val) max_val = static_cast<wchar_t>(0x10FFFF);
break;
}
case L'x': {
@ -1368,7 +1369,8 @@ maybe_t<size_t> read_unquoted_escape(const wchar_t *input, wcstring *result, boo
}
if (res <= max_val) {
result_char_or_none = (wchar_t)((byte_literal ? ENCODE_DIRECT_BASE : 0) + res);
result_char_or_none =
static_cast<wchar_t>((byte_literal ? ENCODE_DIRECT_BASE : 0) + res);
} else {
errored = true;
}
@ -2156,11 +2158,12 @@ wcstring format_size(long long sz) {
for (i = 0; sz_name[i]; i++) {
if (sz < (1024 * 1024) || !sz_name[i + 1]) {
long isz = ((long)sz) / 1024;
long isz = (static_cast<long>(sz)) / 1024;
if (isz > 9)
result.append(format_string(L"%d%ls", isz, sz_name[i]));
else
result.append(format_string(L"%.1f%ls", (double)sz / 1024, sz_name[i]));
result.append(
format_string(L"%.1f%ls", static_cast<double>(sz) / 1024, sz_name[i]));
break;
}
sz /= 1024;
@ -2234,7 +2237,7 @@ double timef() {
struct timeval tv;
assert_with_errno(gettimeofday(&tv, 0) != -1);
// return (double)tv.tv_sec + 0.000001 * tv.tv_usec;
return (double)tv.tv_sec + 1e-6 * tv.tv_usec;
return static_cast<double>(tv.tv_sec) + 1e-6 * tv.tv_usec;
}
void exit_without_destructors(int code) { _exit(code); }

View file

@ -156,7 +156,7 @@ template <>
struct hash<completion_entry_t> {
size_t operator()(const completion_entry_t &c) const {
std::hash<wcstring> hasher;
return hasher((wcstring)c.cmd);
return hasher(wcstring(c.cmd));
}
};
template <>

View file

@ -397,7 +397,7 @@ static bool initialize_curses_using_fallback(const char *term) {
if (is_interactive_session()) debug(1, _(L"Using fallback terminal type '%s'."), term);
int err_ret;
if (setupterm((char *)term, STDOUT_FILENO, &err_ret) == OK) return true;
if (setupterm(const_cast<char *>(term), STDOUT_FILENO, &err_ret) == OK) return true;
if (is_interactive_session()) {
debug(1, _(L"Could not set up terminal using the fallback terminal type '%s'."), term);
}

View file

@ -147,7 +147,7 @@ static wcstring full_escape(const wcstring &in) {
for (wchar_t c : in) {
if (is_universal_safe_to_encode_directly(c)) {
out.push_back(c);
} else if (c <= (wchar_t)ASCII_MAX) {
} else if (c <= static_cast<wchar_t>(ASCII_MAX)) {
// See #1225 for discussion of use of ASCII_MAX here.
append_format(out, L"\\x%.2x", c);
} else if (c < 65536) {
@ -1380,7 +1380,7 @@ class universal_notifier_named_pipe_t : public universal_notifier_t {
// Oops, it already passed! Return something tiny.
readback_delay = 1000;
} else {
readback_delay = (unsigned long)(this->readback_time_usec - now);
readback_delay = static_cast<unsigned long>(this->readback_time_usec - now);
}
}

View file

@ -91,7 +91,8 @@ static owning_lock<event_handler_list_t> s_event_handlers;
static volatile sig_atomic_t s_observed_signals[NSIG] = {};
static void set_signal_observed(int sig, bool val) {
if (sig >= 0 && (size_t)sig < sizeof s_observed_signals / sizeof *s_observed_signals) {
if (sig >= 0 &&
static_cast<size_t>(sig) < sizeof s_observed_signals / sizeof *s_observed_signals) {
s_observed_signals[sig] = val;
}
}
@ -232,7 +233,8 @@ event_handler_list_t event_get_function_handlers(const wcstring &name) {
bool event_is_signal_observed(int sig) {
// We are in a signal handler! Don't allocate memory, etc.
bool result = false;
if (sig >= 0 && (unsigned long)sig < sizeof(s_observed_signals) / sizeof(*s_observed_signals)) {
if (sig >= 0 && static_cast<unsigned long>(sig) <
sizeof(s_observed_signals) / sizeof(*s_observed_signals)) {
result = s_observed_signals[sig];
}
return result;

View file

@ -1264,7 +1264,8 @@ static int exec_subshell_internal(const wcstring &cmd, parser_t &parser, wcstrin
const char *cursor = begin;
while (cursor < end) {
// Look for the next separator.
const char *stop = (const char *)std::memchr(cursor, '\n', end - cursor);
const char *stop =
static_cast<const char *>(std::memchr(cursor, '\n', end - cursor));
const bool hit_separator = (stop != NULL);
if (!hit_separator) {
// If it's not found, just use the end.

View file

@ -150,7 +150,7 @@ wcstring expand_escape_variable(const env_var_t &var) {
/// with [.
static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long> &idx,
size_t array_size) {
const long size = (long)array_size;
const long size = static_cast<long>(array_size);
size_t pos = 1; // skip past the opening square brace
int zero_index = -1;
@ -234,7 +234,7 @@ static size_t parse_slice(const wchar_t *in, wchar_t **end_ptr, std::vector<long
}
if (end_ptr) {
*end_ptr = (wchar_t *)(in + pos);
*end_ptr = const_cast<wchar_t *>(in + pos);
}
return 0;
@ -621,7 +621,7 @@ static bool expand_cmdsubst(wcstring input, parser_t &parser, std::vector<comple
tail_begin = slice_end;
for (i = 0; i < slice_idx.size(); i++) {
long idx = slice_idx.at(i);
if ((size_t)idx > sub_res.size() || idx < 1) {
if (static_cast<size_t>(idx) > sub_res.size() || idx < 1) {
continue;
}
idx = idx - 1;
@ -811,7 +811,8 @@ wcstring replace_home_directory_with_tilde(const wcstring &str, const environmen
/// equivalents. This is done to support skip_wildcards.
static void remove_internal_separator(wcstring *str, bool conv) {
// Remove all instances of INTERNAL_SEPARATOR.
str->erase(std::remove(str->begin(), str->end(), (wchar_t)INTERNAL_SEPARATOR), str->end());
str->erase(std::remove(str->begin(), str->end(), static_cast<wchar_t>(INTERNAL_SEPARATOR)),
str->end());
// If conv is true, replace all instances of ANY_STRING with '*',
// ANY_STRING_RECURSIVE with '*'.

View file

@ -77,7 +77,7 @@ int fish_mkstemp_cloexec(char *name_template) {
// cppcheck-suppress unusedFunction
[[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) {
size_t len = std::wcslen(in);
wchar_t *out = (wchar_t *)malloc(sizeof(wchar_t) * (len + 1));
wchar_t *out = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (len + 1)));
if (out == 0) {
return 0;
}
@ -162,7 +162,7 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) {
#ifndef HAVE_WCSNDUP
wchar_t *wcsndup(const wchar_t *in, size_t c) {
wchar_t *res = (wchar_t *)malloc(sizeof(wchar_t) * (c + 1));
wchar_t *res = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (c + 1)));
if (res == 0) {
return 0;
}

View file

@ -83,8 +83,8 @@ static const char *s_profiling_output_filename = NULL;
/// \return a timeval converted to milliseconds.
long long tv_to_msec(const struct timeval &tv) {
long long msec = (long long)tv.tv_sec * 1000; // milliseconds per second
msec += tv.tv_usec / 1000; // microseconds per millisecond
long long msec = static_cast<long long>(tv.tv_sec) * 1000; // milliseconds per second
msec += tv.tv_usec / 1000; // microseconds per millisecond
return msec;
}
@ -299,7 +299,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
tmp = strtol(optarg, &end, 10);
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
debug_level = (int)tmp;
debug_level = static_cast<int>(tmp);
} else {
activate_flog_categories_by_pattern(str2wcstring(optarg));
}
@ -338,7 +338,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
// Compute width of longest name.
int name_width = 0;
for (const auto *cat : cats) {
name_width = std::max(name_width, (int)wcslen(cat->name));
name_width = std::max(name_width, static_cast<int>(wcslen(cat->name)));
}
// A little extra space.
name_width += 2;
@ -371,7 +371,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
tmp = strtol(optarg, &end, 10);
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
set_debug_stack_frames(static_cast<int>(tmp));
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"),
optarg);

View file

@ -73,7 +73,7 @@ static wcstring read_file(FILE *f) {
}
break;
}
result.push_back((wchar_t)c);
result.push_back(static_cast<wchar_t>(c));
}
return result;
}
@ -140,7 +140,7 @@ static void dump_node(indent_t node_indent, const parse_node_t &node, const wcst
wcstring source_txt = L"";
if (node.source_start != SOURCE_OFFSET_INVALID && node.source_length != SOURCE_OFFSET_INVALID) {
int nextc_idx = node.source_start + node.source_length;
if ((size_t)nextc_idx < source.size()) {
if (static_cast<size_t>(nextc_idx) < source.size()) {
nextc = source[node.source_start + node.source_length];
}
if (node.source_start > 0) prevc = source[node.source_start - 1];
@ -565,7 +565,7 @@ int main(int argc, char *argv[]) {
tmp = strtol(optarg, &end, 10);
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
debug_level = (int)tmp;
debug_level = static_cast<int>(tmp);
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
exit(1);
@ -580,7 +580,7 @@ int main(int argc, char *argv[]) {
tmp = strtol(optarg, &end, 10);
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
set_debug_stack_frames(static_cast<int>(tmp));
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag"),
optarg);

View file

@ -319,7 +319,7 @@ static bool parse_debug_level_flag() {
long tmp = strtol(optarg, &end, 10);
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
debug_level = (int)tmp;
debug_level = static_cast<int>(tmp);
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag\n"), optarg);
return false;
@ -333,7 +333,7 @@ static bool parse_debug_frames_flag() {
char *end;
long tmp = strtol(optarg, &end, 10);
if (tmp > 0 && tmp <= 128 && !*end && !errno) {
set_debug_stack_frames((int)tmp);
set_debug_stack_frames(static_cast<int>(tmp));
} else {
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-stack-frames flag\n"), optarg);
return false;

View file

@ -1422,7 +1422,7 @@ static void highlight_universal_internal(const wcstring &buffstr,
wchar_t inc_char = c;
int level = 0;
bool match_found = false;
for (long i = pos; i >= 0 && (size_t)i < buffstr.size(); i += step) {
for (long i = pos; i >= 0 && static_cast<size_t>(i) < buffstr.size(); i += step) {
const wchar_t test_char = buffstr.at(i);
if (test_char == inc_char) level++;
if (test_char == dec_char) level--;

View file

@ -378,7 +378,7 @@ void history_impl_t::save_unless_disabled() {
// the counter.
const int kVacuumFrequency = 25;
if (countdown_to_vacuum < 0) {
unsigned int seed = (unsigned int)time(NULL);
unsigned int seed = static_cast<unsigned int>(time(NULL));
// Generate a number in the range [0, kVacuumFrequency).
countdown_to_vacuum = rand_r(&seed) / (RAND_MAX / kVacuumFrequency + 1);
}
@ -582,7 +582,7 @@ void history_impl_t::load_old_if_needed() {
bool history_search_t::go_backwards() {
// Backwards means increasing our index.
const size_t max_index = (size_t)-1;
const size_t max_index = static_cast<size_t>(-1);
if (current_index_ == max_index) return false;

View file

@ -183,7 +183,7 @@ static size_t read_line(const char *base, size_t cursor, size_t len, std::string
// Locate the newline.
assert(cursor <= len);
const char *start = base + cursor;
const char *a_newline = (char *)std::memchr(start, '\n', len - cursor);
const char *a_newline = static_cast<const char *>(std::memchr(start, '\n', len - cursor));
if (a_newline != NULL) { // we found a newline
result.assign(start, a_newline - start);
// Return the amount to advance the cursor; skip over the newline.
@ -303,7 +303,7 @@ static bool parse_timestamp(const char *str, time_t *out_when) {
// Try to parse a timestamp.
long timestamp = 0;
if (isdigit(*cursor) && (timestamp = strtol(cursor, NULL, 0)) > 0) {
*out_when = (time_t)timestamp;
*out_when = static_cast<time_t>(timestamp);
return true;
}
return false;
@ -350,7 +350,8 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten
const char *line_start = contents.address_at(cursor);
// Advance the cursor to the next line.
const char *a_newline = (const char *)std::memchr(line_start, '\n', length - cursor);
const char *a_newline =
static_cast<const char *>(std::memchr(line_start, '\n', length - cursor));
if (a_newline == NULL) break;
// Advance the cursor past this line. +1 is for the newline.
@ -371,7 +372,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten
// leading "- cmd: - cmd: - cmd:". Trim all but one leading "- cmd:".
const char *double_cmd = "- cmd: - cmd: ";
const size_t double_cmd_len = std::strlen(double_cmd);
while ((size_t)(a_newline - line_start) > double_cmd_len &&
while (static_cast<size_t>(a_newline - line_start) > double_cmd_len &&
!std::memcmp(line_start, double_cmd, double_cmd_len)) {
// Skip over just one of the - cmd. In the end there will be just one left.
line_start += std::strlen("- cmd: ");
@ -381,7 +382,7 @@ static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &conten
// 123456". Ignore those.
const char *cmd_when = "- cmd: when:";
const size_t cmd_when_len = std::strlen(cmd_when);
if ((size_t)(a_newline - line_start) >= cmd_when_len &&
if (static_cast<size_t>(a_newline - line_start) >= cmd_when_len &&
!std::memcmp(line_start, cmd_when, cmd_when_len)) {
continue;
}
@ -485,18 +486,18 @@ static history_item_t decode_item_fish_1_x(const char *begin, size_t length) {
mbstate_t state = {};
if (MB_CUR_MAX == 1) { // single-byte locale
c = (unsigned char)*pos;
c = static_cast<unsigned char>(*pos);
res = 1;
} else {
res = std::mbrtowc(&c, pos, end - pos, &state);
}
if (res == (size_t)-1) {
if (res == static_cast<size_t>(-1)) {
pos++;
continue;
} else if (res == (size_t)-2) {
} else if (res == static_cast<size_t>(-2)) {
break;
} else if (res == (size_t)0) {
} else if (res == static_cast<size_t>(0)) {
pos++;
continue;
}
@ -508,7 +509,7 @@ static history_item_t decode_item_fish_1_x(const char *begin, size_t length) {
while (*time_string && !iswdigit(*time_string)) time_string++;
if (*time_string) {
time_t tm = (time_t)fish_wcstol(time_string);
time_t tm = static_cast<time_t>(fish_wcstol(time_string));
if (!errno && tm >= 0) {
timestamp = tm;
}
@ -538,7 +539,7 @@ static history_item_t decode_item_fish_1_x(const char *begin, size_t length) {
/// Adapted from history_populate_from_mmap in history.c
static size_t offset_of_next_item_fish_1_x(const char *begin, size_t mmap_length,
size_t *inout_cursor) {
if (mmap_length == 0 || *inout_cursor >= mmap_length) return (size_t)-1;
if (mmap_length == 0 || *inout_cursor >= mmap_length) return static_cast<size_t>(-1);
const char *end = begin + mmap_length;
const char *pos;

View file

@ -71,8 +71,8 @@ char_event_t input_event_queue_t::readb() {
const unsigned long usecs_delay = notifier.usec_delay_between_polls();
if (usecs_delay > 0) {
unsigned long usecs_per_sec = 1000000;
tv.tv_sec = (int)(usecs_delay / usecs_per_sec);
tv.tv_usec = (int)(usecs_delay % usecs_per_sec);
tv.tv_sec = static_cast<int>(usecs_delay / usecs_per_sec);
tv.tv_usec = static_cast<int>(usecs_delay % usecs_per_sec);
}
res = select(fd_max + 1, &fdset, 0, 0, usecs_delay > 0 ? &tv : NULL);
@ -144,7 +144,7 @@ void update_wait_on_escape_ms(const environment_t &vars) {
L"is not an integer or is < 10 or >= 5000 ms\n",
escape_time_ms->as_string().c_str());
} else {
wait_on_escape_ms = (int)tmp;
wait_on_escape_ms = static_cast<int>(tmp);
}
}
@ -186,12 +186,12 @@ char_event_t input_event_queue_t::readch() {
size_t sz = std::mbrtowc(&res, &bb, 1, &state);
switch (sz) {
case (size_t)(-1): {
case static_cast<size_t>(-1): {
std::memset(&state, '\0', sizeof(state));
debug(2, L"Illegal input");
return char_event_type_t::check_exit;
}
case (size_t)(-2): {
case static_cast<size_t>(-2): {
break;
}
case 0: {

View file

@ -36,7 +36,9 @@
static color_support_t color_support = 0;
/// Returns true if we think tparm can handle outputting a color index
static bool term_supports_color_natively(unsigned int c) { return (unsigned)max_colors >= c + 1; }
static bool term_supports_color_natively(unsigned int c) {
return static_cast<unsigned>(max_colors) >= c + 1;
}
color_support_t output_get_color_support() { return color_support; }
@ -361,7 +363,7 @@ int outputter_t::term_puts(const char *str, int affcnt) {
scoped_push<outputter_t *> push(&s_tputs_receiver, this);
// On some systems, tputs takes a char*, on others a const char*.
// Like tparm, we just cast it to unconst, that should work everywhere.
return tputs((char *)str, affcnt, tputs_writer);
return tputs(const_cast<char *>(str), affcnt, tputs_writer);
}
/// Write a wide character to the outputter. This should only be used when writing characters from
@ -384,7 +386,7 @@ int outputter_t::writech(wint_t ch) {
} else {
mbstate_t state = {};
len = std::wcrtomb(buff, ch, &state);
if (len == (size_t)-1) {
if (len == static_cast<size_t>(-1)) {
return 1;
}
}
@ -400,7 +402,7 @@ void outputter_t::writestr(const wchar_t *str) {
assert(str && "Empty input string");
size_t len = wcstombs(0, str, 0); // figure amount of space needed
if (len == (size_t)-1) {
if (len == static_cast<size_t>(-1)) {
debug(1, L"Tried to print invalid wide character string");
return;
}

View file

@ -421,7 +421,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
this->available_term_height - 1 -
(search_field_shown ? 1 : 0); // we always subtract 1 to make room for a comment row
if (!this->fully_disclosed) {
term_height = std::min(term_height, (size_t)PAGER_UNDISCLOSED_MAX_ROWS);
term_height = std::min(term_height, static_cast<size_t>(PAGER_UNDISCLOSED_MAX_ROWS));
}
size_t row_count = divide_round_up(lst.size(), cols);
@ -494,7 +494,7 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
assert(rendering->remaining_to_disclose != 1);
if (rendering->remaining_to_disclose > 1) {
progress_text = format_string(_(L"%lsand %lu more rows"), get_ellipsis_str(),
(unsigned long)rendering->remaining_to_disclose);
static_cast<unsigned long>(rendering->remaining_to_disclose));
} else if (start_row > 0 || stop_row < row_count) {
// We have a scrollable interface. The +1 here is because we are zero indexed, but want
// to present things as 1-indexed. We do not add 1 to stop_row or row_count because
@ -566,7 +566,7 @@ page_rendering_t pager_t::render() const {
continue;
}
rendering.cols = (size_t)cols;
rendering.cols = cols;
rendering.rows = min_rows_required_for_cols;
rendering.selected_completion_idx =
this->visual_selected_completion_index(rendering.rows, rendering.cols);
@ -659,7 +659,7 @@ bool pager_t::select_next_completion_in_direction(selection_motion_t direction,
// 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_col = this->get_selected_column(rendering);
size_t page_height = std::max(rendering.term_height - 1, (size_t)1);
size_t page_height = std::max(rendering.term_height - 1, static_cast<size_t>(1));
switch (direction) {
case selection_motion_t::page_north: {

View file

@ -699,7 +699,8 @@ static wcstring reconstruct_orig_str(wcstring tokenized_str) {
// However, anyone writing the former is asking for trouble so I don't feel bad about not
// accurately reconstructing what they typed.
wcstring new_str = wcstring(tokenized_str);
std::replace(new_str.begin(), new_str.end(), (wchar_t)VARIABLE_EXPAND_SINGLE, L'$');
std::replace(new_str.begin(), new_str.end(), static_cast<wchar_t>(VARIABLE_EXPAND_SINGLE),
L'$');
orig_str = L"\"" + new_str + L"\"";
}
@ -1308,7 +1309,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
exec_time = get_time();
profile_item->level = parser->eval_level;
profile_item->parse = 0;
profile_item->exec = (int)(exec_time - start_time);
profile_item->exec = static_cast<int>(exec_time - start_time);
profile_item->cmd = profiling_cmd_name_for_redirectable_block(
specific_statement, this->tree(), this->pstree->src);
profile_item->skipped = false;
@ -1386,8 +1387,8 @@ parse_execution_result_t parse_execution_context_t::run_1_job(tnode_t<g::job> jo
if (profile_item != NULL) {
exec_time = get_time();
profile_item->level = parser->eval_level;
profile_item->parse = (int)(parse_time - start_time);
profile_item->exec = (int)(exec_time - parse_time);
profile_item->parse = static_cast<int>(parse_time - start_time);
profile_item->exec = static_cast<int>(exec_time - parse_time);
profile_item->cmd = job ? job->command() : wcstring();
profile_item->skipped = !populated_job;
}

View file

@ -306,10 +306,10 @@ static void dump_tree_recursive(const parse_node_tree_t &nodes, const wcstring &
if (node.type != parse_token_type_string) {
if (node.has_source()) {
append_format(*result, L" [%ld, %ld]", (long)node.source_start,
(long)node.source_length);
append_format(*result, L" [%ld, %ld]", static_cast<long>(node.source_start),
static_cast<long>(node.source_length));
} else {
append_format(*result, L" [%ld, no src]", (long)node.source_start);
append_format(*result, L" [%ld, no src]", static_cast<long>(node.source_start));
}
}
@ -1054,10 +1054,10 @@ static inline parse_token_t next_parse_token(tokenizer_t *tok, maybe_t<tok_t> *o
// uint32_t to save some space. If we have a source file larger than 4 GB, we'll probably just
// crash.
assert(token.offset < SOURCE_OFFSET_INVALID);
result.source_start = (source_offset_t)token.offset;
result.source_start = static_cast<source_offset_t>(token.offset);
assert(token.length <= SOURCE_OFFSET_INVALID);
result.source_length = (source_offset_t)token.length;
result.source_length = static_cast<source_offset_t>(token.length);
return result;
}

View file

@ -77,11 +77,11 @@ size_t parse_util_get_offset_from_line(const wcstring &str, int line) {
size_t i;
int count = 0;
if (line < 0) return (size_t)-1;
if (line < 0) return static_cast<size_t>(-1);
if (line == 0) return 0;
for (i = 0;; i++) {
if (!buff[i]) return (size_t)-1;
if (!buff[i]) return static_cast<size_t>(-1);
if (buff[i] == L'\n') {
count++;
@ -96,11 +96,11 @@ size_t parse_util_get_offset(const wcstring &str, int line, long line_offset) {
size_t off = parse_util_get_offset_from_line(str, line);
size_t off2 = parse_util_get_offset_from_line(str, line + 1);
if (off == (size_t)-1) return (size_t)-1;
if (off2 == (size_t)-1) off2 = str.length() + 1;
if (off == static_cast<size_t>(-1)) return static_cast<size_t>(-1);
if (off2 == static_cast<size_t>(-1)) off2 = str.length() + 1;
if (line_offset < 0) line_offset = 0; //!OCLINT(parameter reassignment)
if ((size_t)line_offset >= off2 - off - 1) {
if (static_cast<size_t>(line_offset) >= off2 - off - 1) {
line_offset = off2 - off - 1; //!OCLINT(parameter reassignment)
}
@ -170,7 +170,7 @@ static int parse_util_locate_brackets_of_type(const wchar_t *in, wchar_t **begin
}
if (end) {
*end = paran_count ? (wchar_t *)in + std::wcslen(in) : paran_end;
*end = paran_count ? const_cast<wchar_t *>(in) + std::wcslen(in) : paran_end;
}
return 1;
@ -328,10 +328,10 @@ static void job_or_process_extent(bool process, const wchar_t *buff, size_t curs
case token_type_t::comment: {
if (tok_begin >= pos) {
finished = 1;
if (b) *b = (wchar_t *)begin + tok_begin;
if (b) *b = const_cast<wchar_t *>(begin) + tok_begin;
} else {
// Statement at cursor might start after this token.
if (a) *a = (wchar_t *)begin + tok_begin + token->length;
if (a) *a = const_cast<wchar_t *>(begin) + tok_begin + token->length;
if (tokens) tokens->clear();
}
continue; // Do not add this to tokens

View file

@ -99,7 +99,7 @@ static const struct block_lookup_entry block_lookup[] = {
{EVENT, 0, EVENT_BLOCK},
{BREAKPOINT, L"breakpoint", BREAKPOINT_BLOCK},
{VARIABLE_ASSIGNMENT, L"variable assignment", VARIABLE_ASSIGNMENT_BLOCK},
{(block_type_t)0, 0, 0}};
{static_cast<block_type_t>(0), 0, 0}};
// Given a file path, return something nicer. Currently we just "unexpand" tildes.
wcstring parser_t::user_presentable_path(const wcstring &path) const {

View file

@ -92,19 +92,19 @@ job_id_t acquire_job_id() {
if (slot != consumed_job_ids->end()) {
// We found a slot. Note that slot 0 corresponds to job ID 1.
*slot = true;
return (job_id_t)(slot - consumed_job_ids->begin() + 1);
return static_cast<job_id_t>(slot - consumed_job_ids->begin() + 1);
}
// We did not find a slot; create a new slot. The size of the vector is now the job ID
// (since it is one larger than the slot).
consumed_job_ids->push_back(true);
return (job_id_t)consumed_job_ids->size();
return static_cast<job_id_t>(consumed_job_ids->size());
}
void release_job_id(job_id_t jid) {
assert(jid > 0);
auto consumed_job_ids = locked_consumed_job_ids.acquire();
size_t slot = (size_t)(jid - 1), count = consumed_job_ids->size();
size_t slot = static_cast<size_t>(jid - 1), count = consumed_job_ids->size();
// Make sure this slot is within our vector and is currently set to consumed.
assert(slot < count);

View file

@ -2057,7 +2057,7 @@ static std::function<highlight_result_t(void)> get_highlight_performer(
void reader_data_t::super_highlight_me_plenty(int match_highlight_pos_adjust, bool no_io) {
const editable_line_t *el = &command_line;
assert(el != NULL);
long match_highlight_pos = (long)el->position + match_highlight_pos_adjust;
long match_highlight_pos = static_cast<long>(el->position) + match_highlight_pos_adjust;
assert(match_highlight_pos >= 0);
sanity_check();
@ -3478,7 +3478,7 @@ void reader_set_buffer(const wcstring &b, size_t pos) {
size_t reader_get_cursor_pos() {
reader_data_t *data = current_data_or_null();
if (!data) return (size_t)-1;
if (!data) return static_cast<size_t>(-1);
return data->command_line.position;
}

View file

@ -83,7 +83,7 @@ static size_t try_sequence(const char *seq, const wchar_t *str) {
/// Returns the number of columns left until the next tab stop, given the current cursor position.
static size_t next_tab_stop(size_t current_line_width) {
// Assume tab stops every 8 characters if undefined.
size_t tab_width = init_tabs > 0 ? (size_t)init_tabs : 8;
size_t tab_width = init_tabs > 0 ? static_cast<size_t>(init_tabs) : 8;
return ((current_line_width / tab_width) + 1) * tab_width;
}
@ -205,7 +205,7 @@ static bool is_color_escape_seq(const wchar_t *code, size_t *resulting_length) {
if (!esc[p]) continue;
for (int k = 0; k < max_colors; k++) {
size_t esc_seq_len = try_sequence(tparm((char *)esc[p], k), code);
size_t esc_seq_len = try_sequence(tparm(const_cast<char *>(esc[p]), k), code);
if (esc_seq_len) {
*resulting_length = esc_seq_len;
return true;
@ -231,8 +231,8 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
if (!esc2[p]) continue;
// Test both padded and unpadded version, just to be safe. Most versions of tparm don't
// actually seem to do anything these days.
size_t esc_seq_len =
std::max(try_sequence(tparm((char *)esc2[p]), code), try_sequence(esc2[p], code));
size_t esc_seq_len = std::max(try_sequence(tparm(const_cast<char *>(esc2[p])), code),
try_sequence(esc2[p], code));
if (esc_seq_len) {
*resulting_length = esc_seq_len;
return true;
@ -417,7 +417,7 @@ static void s_desired_append_char(screen_t *s, wchar_t b, highlight_spec_t c, in
// Current line is soft wrapped (assuming we support it).
s->desired.line(s->desired.cursor.y).is_soft_wrapped = true;
line_no = (int)s->desired.line_count();
line_no = static_cast<int>(s->desired.line_count());
s->desired.add_line();
s->desired.cursor.y++;
s->desired.cursor.x = 0;
@ -512,7 +512,7 @@ static void s_move(screen_t *s, int new_x, int new_y) {
bool use_multi = multi_str != NULL && multi_str[0] != '\0' &&
abs(x_steps) * std::strlen(str) > std::strlen(multi_str);
if (use_multi && cur_term) {
char *multi_param = tparm((char *)multi_str, abs(x_steps));
char *multi_param = tparm(const_cast<char *>(multi_str), abs(x_steps));
writembs(outp, multi_param);
} else {
for (i = 0; i < abs(x_steps); i++) {
@ -651,7 +651,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
s_move(scr, 0, 0);
s_write_str(scr, left_prompt.c_str());
scr->actual_left_prompt = left_prompt;
scr->actual.cursor.x = (int)left_prompt_width;
scr->actual.cursor.x = static_cast<int>(left_prompt_width);
}
for (size_t i = 0; i < scr->desired.line_count(); i++) {
@ -674,7 +674,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
if (o_line.indentation > s_line.indentation && !has_cleared_screen && clr_eol &&
clr_eos) {
s_set_color(scr, vars, highlight_spec_t{});
s_move(scr, 0, (int)i);
s_move(scr, 0, static_cast<int>(i));
s_write_mbs(scr, should_clear_screen_this_line ? clr_eos : clr_eol);
has_cleared_screen = should_clear_screen_this_line;
has_cleared_line = true;
@ -703,7 +703,8 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
}
}
if (next_line_will_change) {
skip_remaining = std::min(skip_remaining, (size_t)(scr->actual_width - 2));
skip_remaining =
std::min(skip_remaining, static_cast<size_t>(scr->actual_width - 2));
}
}
}
@ -732,16 +733,16 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
// to the sticky right cursor. If we clear the screen too early, we can defeat soft
// wrapping.
if (should_clear_screen_this_line && !has_cleared_screen &&
(done || j + 1 == (size_t)screen_width)) {
(done || j + 1 == static_cast<size_t>(screen_width))) {
s_set_color(scr, vars, highlight_spec_t{});
s_move(scr, current_width, (int)i);
s_move(scr, current_width, static_cast<int>(i));
s_write_mbs(scr, clr_eos);
has_cleared_screen = true;
}
if (done) break;
perform_any_impending_soft_wrap(scr, current_width, (int)i);
s_move(scr, current_width, (int)i);
perform_any_impending_soft_wrap(scr, current_width, static_cast<int>(i));
s_move(scr, current_width, static_cast<int>(i));
s_set_color(scr, vars, o_line.color_at(j));
auto width = fish_wcwidth_min_0(o_line.char_at(j));
s_write_char(scr, o_line.char_at(j), width);
@ -770,13 +771,13 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
}
if (clear_remainder && clr_eol) {
s_set_color(scr, vars, highlight_spec_t{});
s_move(scr, current_width, (int)i);
s_move(scr, current_width, static_cast<int>(i));
s_write_mbs(scr, clr_eol);
}
// Output any rprompt if this is the first line.
if (i == 0 && right_prompt_width > 0) { //!OCLINT(Use early exit/continue)
s_move(scr, (int)(screen_width - right_prompt_width), (int)i);
s_move(scr, static_cast<int>(screen_width - right_prompt_width), static_cast<int>(i));
s_set_color(scr, vars, highlight_spec_t{});
s_write_str(scr, right_prompt.c_str());
scr->actual.cursor.x += right_prompt_width;
@ -789,7 +790,8 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
// wrapped. If so, then a cr will go to the beginning of the following line! So instead
// issue a bunch of "move left" commands to get back onto the line, and then jump to the
// front of it.
s_move(scr, scr->actual.cursor.x - (int)right_prompt_width, scr->actual.cursor.y);
s_move(scr, scr->actual.cursor.x - static_cast<int>(right_prompt_width),
scr->actual.cursor.y);
s_write_str(scr, L"\r");
scr->actual.cursor.x = 0;
}
@ -799,7 +801,7 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
if (!has_cleared_screen && need_clear_screen && clr_eol) {
s_set_color(scr, vars, highlight_spec_t{});
for (size_t i = scr->desired.line_count(); i < lines_with_stuff; i++) {
s_move(scr, 0, (int)i);
s_move(scr, 0, static_cast<int>(i));
s_write_mbs(scr, clr_eol);
}
}
@ -1075,8 +1077,8 @@ void s_write(screen_t *s, const wcstring &left_prompt, const wcstring &right_pro
s->desired.cursor = cursor_arr;
if (cursor_is_within_pager) {
s->desired.cursor.x = (int)cursor_pos;
s->desired.cursor.y = (int)s->desired.line_count();
s->desired.cursor.x = static_cast<int>(cursor_pos);
s->desired.cursor.y = static_cast<int>(s->desired.line_count());
}
// Append pager_data (none if empty).
@ -1152,7 +1154,7 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
if (screen_width > non_space_width) {
bool justgrey = true;
if (cur_term && enter_dim_mode) {
std::string dim = tparm((char *)enter_dim_mode);
std::string dim = tparm(enter_dim_mode);
if (!dim.empty()) {
// Use dim if they have it, so the color will be based on their actual normal
// color and the background of the termianl.
@ -1163,22 +1165,22 @@ void s_reset(screen_t *s, screen_reset_mode_t mode) {
if (cur_term && justgrey && set_a_foreground) {
if (max_colors >= 238) {
// draw the string in a particular grey
abandon_line_string.append(str2wcstring(tparm((char *)set_a_foreground, 237)));
abandon_line_string.append(str2wcstring(tparm(set_a_foreground, 237)));
} else if (max_colors >= 9) {
// bright black (the ninth color, looks grey)
abandon_line_string.append(str2wcstring(tparm((char *)set_a_foreground, 8)));
abandon_line_string.append(str2wcstring(tparm(set_a_foreground, 8)));
} else if (max_colors >= 2 && enter_bold_mode) {
// we might still get that color by setting black and going bold for bright
abandon_line_string.append(str2wcstring(tparm((char *)enter_bold_mode)));
abandon_line_string.append(str2wcstring(tparm((char *)set_a_foreground, 0)));
abandon_line_string.append(str2wcstring(tparm(enter_bold_mode)));
abandon_line_string.append(str2wcstring(tparm(set_a_foreground, 0)));
}
}
abandon_line_string.append(get_omitted_newline_str());
if (cur_term && exit_attribute_mode) {
abandon_line_string.append(str2wcstring(
tparm((char *)exit_attribute_mode))); // normal text ANSI escape sequence
abandon_line_string.append(
str2wcstring(tparm(exit_attribute_mode))); // normal text ANSI escape sequence
}
int newline_glitch_width = term_has_xn ? 0 : 1;

View file

@ -109,7 +109,7 @@ static te_expr *new_expr(const int type, const te_expr *parameters[]) {
const int arity = get_arity(type);
const int psize = sizeof(te_expr *) * arity;
const int size = sizeof(te_expr) + psize;
te_expr *ret = (te_expr *)malloc(size);
te_expr *ret = static_cast<te_expr *>(malloc(size));
// This sets float to 0, which depends on the implementation.
// We rely on IEEE-754 floats anyway, so it's okay.
std::memset(ret, 0, size);
@ -142,19 +142,19 @@ static constexpr double e() { return M_E; }
static double fac(double a) { /* simplest version of fac */
if (a < 0.0) return NAN;
if (a > UINT_MAX) return INFINITY;
unsigned int ua = (unsigned int)(a);
unsigned int ua = static_cast<unsigned int>(a);
unsigned long int result = 1, i;
for (i = 1; i <= ua; i++) {
if (i > ULONG_MAX / result) return INFINITY;
result *= i;
}
return (double)result;
return static_cast<double>(result);
}
static double ncr(double n, double r) {
if (n < 0.0 || r < 0.0 || n < r) return NAN;
if (n > UINT_MAX || r > UINT_MAX) return INFINITY;
unsigned long int un = (unsigned int)(n), ur = (unsigned int)(r), i;
unsigned long int un = static_cast<unsigned int>(n), ur = static_cast<unsigned int>(r), i;
unsigned long int result = 1;
if (ur > un / 2) ur = un - ur;
for (i = 1; i <= ur; i++) {
@ -169,31 +169,31 @@ static double npr(double n, double r) { return ncr(n, r) * fac(r); }
static const te_builtin functions[] = {
/* must be in alphabetical order */
{"abs", (const void *)(te_fun1)fabs, TE_FUNCTION1},
{"acos", (const void *)(te_fun1)acos, TE_FUNCTION1},
{"asin", (const void *)(te_fun1)asin, TE_FUNCTION1},
{"atan", (const void *)(te_fun1)atan, TE_FUNCTION1},
{"atan2", (const void *)(te_fun2)atan2, TE_FUNCTION2},
{"ceil", (const void *)(te_fun1)ceil, TE_FUNCTION1},
{"cos", (const void *)(te_fun1)cos, TE_FUNCTION1},
{"cosh", (const void *)(te_fun1)cosh, TE_FUNCTION1},
{"e", (const void *)(te_fun0)e, TE_FUNCTION0},
{"exp", (const void *)(te_fun1)exp, TE_FUNCTION1},
{"fac", (const void *)(te_fun1)fac, TE_FUNCTION1},
{"floor", (const void *)(te_fun1)floor, TE_FUNCTION1},
{"ln", (const void *)(te_fun1)log, TE_FUNCTION1},
{"log", (const void *)(te_fun1)log10, TE_FUNCTION1},
{"log10", (const void *)(te_fun1)log10, TE_FUNCTION1},
{"ncr", (const void *)(te_fun2)ncr, TE_FUNCTION2},
{"npr", (const void *)(te_fun2)npr, TE_FUNCTION2},
{"pi", (const void *)(te_fun0)pi, TE_FUNCTION0},
{"pow", (const void *)(te_fun2)pow, TE_FUNCTION2},
{"round", (const void *)(te_fun1)round, TE_FUNCTION1},
{"sin", (const void *)(te_fun1)sin, TE_FUNCTION1},
{"sinh", (const void *)(te_fun1)sinh, TE_FUNCTION1},
{"sqrt", (const void *)(te_fun1)sqrt, TE_FUNCTION1},
{"tan", (const void *)(te_fun1)tan, TE_FUNCTION1},
{"tanh", (const void *)(te_fun1)tanh, TE_FUNCTION1}};
{"abs", reinterpret_cast<const void *>(static_cast<te_fun1>(fabs)), TE_FUNCTION1},
{"acos", reinterpret_cast<const void *>(static_cast<te_fun1>(acos)), TE_FUNCTION1},
{"asin", reinterpret_cast<const void *>(static_cast<te_fun1>(asin)), TE_FUNCTION1},
{"atan", reinterpret_cast<const void *>(static_cast<te_fun1>(atan)), TE_FUNCTION1},
{"atan2", reinterpret_cast<const void *>(static_cast<te_fun2>(atan2)), TE_FUNCTION2},
{"ceil", reinterpret_cast<const void *>(static_cast<te_fun1>(ceil)), TE_FUNCTION1},
{"cos", reinterpret_cast<const void *>(static_cast<te_fun1>(cos)), TE_FUNCTION1},
{"cosh", reinterpret_cast<const void *>(static_cast<te_fun1>(cosh)), TE_FUNCTION1},
{"e", reinterpret_cast<const void *>(static_cast<te_fun0>(e)), TE_FUNCTION0},
{"exp", reinterpret_cast<const void *>(static_cast<te_fun1>(exp)), TE_FUNCTION1},
{"fac", reinterpret_cast<const void *>(static_cast<te_fun1>(fac)), TE_FUNCTION1},
{"floor", reinterpret_cast<const void *>(static_cast<te_fun1>(floor)), TE_FUNCTION1},
{"ln", reinterpret_cast<const void *>(static_cast<te_fun1>(log)), TE_FUNCTION1},
{"log", reinterpret_cast<const void *>(static_cast<te_fun1>(log10)), TE_FUNCTION1},
{"log10", reinterpret_cast<const void *>(static_cast<te_fun1>(log10)), TE_FUNCTION1},
{"ncr", reinterpret_cast<const void *>(static_cast<te_fun2>(ncr)), TE_FUNCTION2},
{"npr", reinterpret_cast<const void *>(static_cast<te_fun2>(npr)), TE_FUNCTION2},
{"pi", reinterpret_cast<const void *>(static_cast<te_fun0>(pi)), TE_FUNCTION0},
{"pow", reinterpret_cast<const void *>(static_cast<te_fun2>(pow)), TE_FUNCTION2},
{"round", reinterpret_cast<const void *>(static_cast<te_fun1>(round)), TE_FUNCTION1},
{"sin", reinterpret_cast<const void *>(static_cast<te_fun1>(sin)), TE_FUNCTION1},
{"sinh", reinterpret_cast<const void *>(static_cast<te_fun1>(sinh)), TE_FUNCTION1},
{"sqrt", reinterpret_cast<const void *>(static_cast<te_fun1>(sqrt)), TE_FUNCTION1},
{"tan", reinterpret_cast<const void *>(static_cast<te_fun1>(tan)), TE_FUNCTION1},
{"tanh", reinterpret_cast<const void *>(static_cast<te_fun1>(tanh)), TE_FUNCTION1}};
static const te_builtin *find_builtin(const char *name, int len) {
const auto end = std::end(functions);
@ -231,7 +231,7 @@ void next_token(state *s) {
/* Try reading a number. */
if ((s->next[0] >= '0' && s->next[0] <= '9') || s->next[0] == '.') {
s->value = strtod(s->next, (char **)&s->next);
s->value = strtod(s->next, const_cast<char **>(&s->next));
s->type = TOK_NUMBER;
} else {
/* Look for a variable or builtin function call. */
@ -268,29 +268,29 @@ void next_token(state *s) {
// The "te_fun2" casts are necessary to pick the right overload.
case '+':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)add;
s->function = reinterpret_cast<const void *>(static_cast<te_fun2>(add));
break;
case '-':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)sub;
s->function = reinterpret_cast<const void *>(static_cast<te_fun2>(sub));
break;
case 'x':
case '*':
// We've already checked for whitespace above.
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)mul;
s->function = reinterpret_cast<const void *>(static_cast<te_fun2>(mul));
break;
case '/':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)divide;
s->function = reinterpret_cast<const void *>(static_cast<te_fun2>(divide));
break;
case '^':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)pow;
s->function = reinterpret_cast<const void *>(static_cast<te_fun2>(pow));
break;
case '%':
s->type = TOK_INFIX;
s->function = (const void *)(te_fun2)fmod;
s->function = reinterpret_cast<const void *>(static_cast<te_fun2>(fmod));
break;
case '(':
s->type = TOK_OPEN;
@ -434,7 +434,7 @@ static te_expr *power(state *s) {
ret = base(s);
} else {
ret = NEW_EXPR(TE_FUNCTION1, base(s));
ret->function = (const void *)negate;
ret->function = reinterpret_cast<const void *>(negate);
}
return ret;
@ -446,19 +446,20 @@ static te_expr *factor(state *s) {
te_expr *insertion = 0;
while (s->type == TOK_INFIX && (s->function == (const void *)(te_fun2)pow)) {
while (s->type == TOK_INFIX &&
(s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(pow)))) {
te_fun2 t = (te_fun2)s->function;
next_token(s);
if (insertion) {
/* Make exponentiation go right-to-left. */
te_expr *insert = NEW_EXPR(TE_FUNCTION2, insertion->parameters[1], power(s));
insert->function = (const void *)t;
insert->function = reinterpret_cast<const void *>(t);
insertion->parameters[1] = insert;
insertion = insert;
} else {
ret = NEW_EXPR(TE_FUNCTION2, ret, power(s));
ret->function = (const void *)t;
ret->function = reinterpret_cast<const void *>(t);
insertion = ret;
}
}
@ -470,13 +471,14 @@ static te_expr *term(state *s) {
/* <term> = <factor> {("*" | "/" | "%") <factor>} */
te_expr *ret = factor(s);
while (s->type == TOK_INFIX && (s->function == (const void *)(te_fun2)mul ||
s->function == (const void *)(te_fun2)divide ||
s->function == (const void *)(te_fun2)fmod)) {
while (s->type == TOK_INFIX &&
(s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(mul)) ||
s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(divide)) ||
s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(fmod)))) {
te_fun2 t = (te_fun2)s->function;
next_token(s);
ret = NEW_EXPR(TE_FUNCTION2, ret, factor(s));
ret->function = (const void *)t;
ret->function = reinterpret_cast<const void *>(t);
}
return ret;
@ -490,7 +492,7 @@ static te_expr *expr(state *s) {
te_fun2 t = (te_fun2)s->function;
next_token(s);
ret = NEW_EXPR(TE_FUNCTION2, ret, term(s));
ret->function = (const void *)t;
ret->function = reinterpret_cast<const void *>(t);
}
return ret;

View file

@ -185,23 +185,23 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
// Get number of bytes for one wide character.
n = 1; // default: 1 byte. Used when skipping bytes
if ((*p & 0x80) == 0)
high = (utf8_wchar_t)*p;
high = static_cast<utf8_wchar_t>(*p);
else if ((*p & 0xe0) == _SEQ2) {
n = 2;
high = (utf8_wchar_t)(*p & 0x1f);
high = static_cast<utf8_wchar_t>(*p & 0x1f);
} else if ((*p & 0xf0) == _SEQ3) {
n = 3;
high = (utf8_wchar_t)(*p & 0x0f);
high = static_cast<utf8_wchar_t>(*p & 0x0f);
} else if ((*p & 0xf8) == _SEQ4) {
n = 4;
high = (utf8_wchar_t)(*p & 0x07);
high = static_cast<utf8_wchar_t>(*p & 0x07);
} else {
if ((flags & UTF8_IGNORE_ERROR) == 0) return 0;
continue;
}
// Does the sequence header tell us truth about length?
if ((size_t)(lim - p) <= n - 1) {
if (static_cast<size_t>(lim - p) <= n - 1) {
if ((flags & UTF8_IGNORE_ERROR) == 0) return 0;
n = 1;
continue; // skip
@ -225,7 +225,7 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
uint32_t out_val = 0;
n_bits = 0;
for (i = 1; i < n; i++) {
out_val |= (utf8_wchar_t)(p[n - i] & 0x3f) << n_bits;
out_val |= static_cast<utf8_wchar_t>(p[n - i] & 0x3f) << n_bits;
n_bits += 6; // 6 low bits in every byte
}
out_val |= high << n_bits;
@ -242,7 +242,7 @@ static size_t utf8_to_wchar_internal(const char *in, size_t insize, utf8_wstring
if (skip) {
total--;
} else if (out_val > (uint32_t)UTF8_WCHAR_MAX) {
} else if (out_val > static_cast<uint32_t>(UTF8_WCHAR_MAX)) {
// wchar_t is UCS-2, but the UTF-8 specified an astral character.
return 0;
} else {
@ -276,7 +276,7 @@ static size_t wchar_to_utf8_internal(const utf8_wchar_t *in, size_t insize, char
w = in;
wlim = w + insize;
p = (unsigned char *)out;
p = reinterpret_cast<unsigned char *>(out);
lim = p + outsize;
total = 0;
for (; w < wlim; w++) {

View file

@ -34,7 +34,7 @@ wcstring_range wcstring_tok(wcstring &str, const wcstring &needle, wcstring_rang
}
wcstring truncate(const wcstring &input, int max_len, ellipsis_type etype) {
if (input.size() <= (size_t)max_len) {
if (input.size() <= static_cast<size_t>(max_len)) {
return input;
}

View file

@ -206,7 +206,8 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
if (temp == NULL || c == ':') {
if (wopterr) {
std::fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0], (wint_t)c);
std::fwprintf(stderr, _(L"%ls: Invalid option -- %lc\n"), argv[0],
static_cast<wint_t>(c));
}
woptopt = c;
@ -238,7 +239,7 @@ int wgetopter_t::_handle_short_opt(int argc, wchar_t **argv) {
if (wopterr) {
// 1003.2 specifies the format of this message.
std::fwprintf(stderr, _(L"%ls: Option requires an argument -- %lc\n"), argv[0],
(wint_t)c);
static_cast<wint_t>(c));
}
woptopt = c;
c = missing_arg_return_colon ? ':' : '?';
@ -308,7 +309,8 @@ const struct woption *wgetopter_t::_find_matching_long_opt(const struct woption
// Test all long options for either exact match or abbreviated matches.
for (const struct woption *p = longopts; p->name; p++, option_index++) {
if (!std::wcsncmp(p->name, nextchar, nameend - nextchar)) {
if ((unsigned int)(nameend - nextchar) == (unsigned int)wcslen(p->name)) {
if (static_cast<unsigned int>(nameend - nextchar) ==
static_cast<unsigned int>(wcslen(p->name))) {
// Exact match found.
pfound = p;
*indfound = option_index;

View file

@ -33,7 +33,13 @@
typedef std::string cstring;
const file_id_t kInvalidFileID = {(dev_t)-1LL, (ino_t)-1LL, (uint64_t)-1LL, -1, -1, -1, -1};
const file_id_t kInvalidFileID = {static_cast<dev_t>(-1LL),
static_cast<ino_t>(-1LL),
static_cast<uint64_t>(-1LL),
-1,
-1,
-1,
-1};
/// Map used as cache by wgettext.
static owning_lock<std::unordered_map<wcstring, wcstring>> wgettext_map;
@ -652,7 +658,7 @@ int fish_wcstoi(const wchar_t *str, const wchar_t **endptr, int base) {
}
}
if (endptr) *endptr = _endptr;
return (int)result;
return static_cast<int>(result);
}
/// An enhanced version of wcstol().