[clang-tidy] use auto when casting

Found with modernize-use-auto

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2020-04-02 16:04:04 -07:00 committed by Fabian Homborg
parent b42445e675
commit 220f0a132d
26 changed files with 71 additions and 73 deletions

View file

@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cert-*,performance-*,portability-*'
Checks: 'clang-diagnostic-*,clang-analyzer-*,cert-*,performance-*,portability-*,modernize-use-auto'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
@ -9,5 +9,7 @@ CheckOptions:
value: 'L;LL;LU;LLU'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: modernize-use-auto.RemoveStars
value: '1'
...

View file

@ -488,7 +488,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
switch (conversion) {
case L'd':
case L'i': {
intmax_t arg = string_to_scalar_type<intmax_t>(argument, this);
auto arg = string_to_scalar_type<intmax_t>(argument, this);
if (!have_field_width) {
if (!have_precision)
this->append_format_output(fmt.c_str(), arg);
@ -506,7 +506,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
case L'u':
case L'x':
case L'X': {
uintmax_t arg = string_to_scalar_type<uintmax_t>(argument, this);
auto arg = string_to_scalar_type<uintmax_t>(argument, this);
if (!have_field_width) {
if (!have_precision)
this->append_format_output(fmt.c_str(), arg);
@ -528,7 +528,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
case L'F':
case L'g':
case L'G': {
long double arg = string_to_scalar_type<long double>(argument, this);
auto arg = string_to_scalar_type<long double>(argument, this);
if (!have_field_width) {
if (!have_precision) {
this->append_format_output(fmt.c_str(), arg);
@ -579,7 +579,7 @@ void builtin_printf_state_t::print_direc(const wchar_t *start, size_t length, wc
static inline void modify_allowed_format_specifiers(bool ok[UCHAR_MAX + 1], const char *str,
bool flag) {
for (const char *c = str; *c != '\0'; c++) {
unsigned char idx = static_cast<unsigned char>(*c);
auto idx = static_cast<unsigned char>(*c);
ok[idx] = flag;
}
}
@ -654,7 +654,7 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch
++f;
++direc_length;
if (argc > 0) {
intmax_t width = string_to_scalar_type<intmax_t>(*argv, this);
auto width = string_to_scalar_type<intmax_t>(*argv, this);
if (INT_MIN <= width && width <= INT_MAX)
field_width = static_cast<int>(width);
else
@ -679,7 +679,7 @@ int builtin_printf_state_t::print_formatted(const wchar_t *format, int argc, wch
++f;
++direc_length;
if (argc > 0) {
intmax_t prec = string_to_scalar_type<intmax_t>(*argv, this);
auto prec = string_to_scalar_type<intmax_t>(*argv, this);
if (prec < 0) {
// A negative precision is taken as if the precision were omitted,
// so -1 is safe here even if prec < INT_MIN.

View file

@ -350,7 +350,7 @@ int builtin_status(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.err.append_format(BUILTIN_ERR_ARG_COUNT2, cmd, subcmd_str, 1, args.size());
return STATUS_INVALID_ARGS;
}
const auto *metadata = features_t::metadata_for(args.front().c_str());
auto metadata = features_t::metadata_for(args.front().c_str());
if (!metadata) {
retval = TEST_FEATURE_NOT_RECOGNIZED;
} else {

View file

@ -871,7 +871,7 @@ class pcre2_matcher_t : public string_matcher_t {
if (opts.invert_match) return true;
// Report any additional matches.
for (auto *ovector = pcre2_get_ovector_pointer(regex.match); opts.all; total_matched++) {
for (auto ovector = pcre2_get_ovector_pointer(regex.match); opts.all; total_matched++) {
uint32_t options = 0;
PCRE2_SIZE offset = ovector[1]; // start at end of previous match
@ -1052,7 +1052,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 = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * bufsize));
auto output = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * bufsize));
int pcre2_rc;
PCRE2_SIZE outlen = bufsize;
@ -1071,8 +1071,7 @@ bool regex_replacer_t::replace_matches(const wcstring &arg) {
done = true;
} else {
bufsize = outlen;
wchar_t *new_output =
static_cast<wchar_t *>(realloc(output, sizeof(wchar_t) * bufsize));
auto new_output = static_cast<wchar_t *>(realloc(output, sizeof(wchar_t) * bufsize));
if (new_output) output = new_output;
}
}
@ -1307,7 +1306,7 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
pos = static_cast<size_type>(opts.start - 1);
} else if (opts.start < 0) {
assert(opts.start != LONG_MIN); // checked above
size_type n = static_cast<size_type>(-opts.start);
auto n = static_cast<size_type>(-opts.start);
pos = n > s->length() ? 0 : s->length() - n;
}

View file

@ -87,15 +87,15 @@ static int parse_hex_digit(wchar_t x) {
}
static unsigned long squared_difference(long p1, long p2) {
unsigned long diff = static_cast<unsigned long>(labs(p1 - p2));
auto 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 = static_cast<unsigned long>(-1);
unsigned char best_index = static_cast<unsigned char>(-1);
auto best_distance = static_cast<unsigned long>(-1);
auto best_index = static_cast<unsigned char>(-1);
for (size_t idx = 0; idx < color_count; idx++) {
uint32_t color = colors[idx];
long test_r = (color >> 16) & 0xFF, test_g = (color >> 8) & 0xFF,

View file

@ -361,7 +361,7 @@ char *wcs2str(const wchar_t *in, size_t len) {
}
// Here we probably allocate a buffer probably much larger than necessary.
char *out = static_cast<char *>(malloc(MAX_UTF8_BYTES * len + 1));
auto 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.
@ -1210,7 +1210,7 @@ wcstring debug_escape(const wcstring &in) {
wcstring result;
result.reserve(in.size());
for (wchar_t wc : in) {
uint32_t c = static_cast<uint32_t>(wc);
auto c = static_cast<uint32_t>(wc);
if (c <= 127 && isprint(c)) {
result.push_back(wc);
continue;
@ -2148,7 +2148,7 @@ void assert_is_background_thread(const char *who) {
}
void assert_is_locked(void *vmutex, const char *who, const char *caller) {
std::mutex *mutex = static_cast<std::mutex *>(vmutex);
auto mutex = static_cast<std::mutex *>(vmutex);
// Note that std::mutex.try_lock() is allowed to return false when the mutex isn't
// actually locked; fortunately we are checking the opposite so we're safe.

View file

@ -422,7 +422,7 @@ bool completer_t::condition_test(const wcstring &condition) {
ASSERT_IS_MAIN_THREAD();
bool test_res;
condition_cache_t::iterator cached_entry = condition_cache.find(condition);
auto cached_entry = condition_cache.find(condition);
if (cached_entry == condition_cache.end()) {
// Compute new value and reinsert it.
test_res =
@ -476,7 +476,7 @@ void complete_add(const wchar_t *cmd, bool cmd_is_path, const wcstring &option,
/// option strings. Returns true if it is now empty and should be deleted, false if it's not empty.
/// Must be called while locked.
bool completion_entry_t::remove_option(const wcstring &option, complete_option_type_t type) {
option_list_t::iterator iter = this->options.begin();
auto iter = this->options.begin();
while (iter != this->options.end()) {
if (iter->option == option && iter->type == type) {
iter = this->options.erase(iter);
@ -493,10 +493,10 @@ void complete_remove(const wcstring &cmd, bool cmd_is_path, const wcstring &opti
auto completion_set = s_completion_set.acquire();
completion_entry_t tmp_entry(cmd, cmd_is_path);
completion_entry_set_t::iterator iter = completion_set->find(tmp_entry);
auto iter = completion_set->find(tmp_entry);
if (iter != completion_set->end()) {
// const_cast: See SET_ELEMENTS_ARE_IMMUTABLE.
completion_entry_t &entry = const_cast<completion_entry_t &>(*iter);
auto &entry = const_cast<completion_entry_t &>(*iter);
bool delete_it = entry.remove_option(option, type);
if (delete_it) {
@ -1788,7 +1788,7 @@ bool complete_remove_wrapper(const wcstring &command, const wcstring &target_to_
auto locked_map = wrapper_map.acquire();
wrapper_map_t &wraps = *locked_map;
bool result = false;
wrapper_map_t::iterator current_targets_iter = wraps.find(command);
auto current_targets_iter = wraps.find(command);
if (current_targets_iter != wraps.end()) {
wcstring_list_t *targets = &current_targets_iter->second;
auto where = std::find(targets->begin(), targets->end(), target_to_remove);

View file

@ -107,7 +107,7 @@ const electric_var_t *electric_var_t::for_name(const wcstring &name) {
/// Check if a variable may not be set using the set command.
static bool is_read_only(const wcstring &key) {
if (const auto *ev = electric_var_t::for_name(key)) {
if (auto ev = electric_var_t::for_name(key)) {
return ev->readonly();
}
// Hack.

View file

@ -253,13 +253,13 @@ env_universal_t::env_universal_t(wcstring path)
: narrow_vars_path(wcs2string(path)), explicit_vars_path(std::move(path)) {}
maybe_t<env_var_t> env_universal_t::get(const wcstring &name) const {
var_table_t::const_iterator where = vars.find(name);
auto where = vars.find(name);
if (where != vars.end()) return where->second;
return none();
}
maybe_t<env_var_t::env_var_flags_t> env_universal_t::get_flags(const wcstring &name) const {
var_table_t::const_iterator where = vars.find(name);
auto where = vars.find(name);
if (where != vars.end()) {
return where->second.get_flags();
}
@ -360,7 +360,7 @@ void env_universal_t::generate_callbacks_and_update_exports(const var_table_t &n
void env_universal_t::acquire_variables(var_table_t &vars_to_acquire) {
// Copy modified values from existing vars to vars_to_acquire.
for (const auto &key : this->modified) {
var_table_t::iterator src_iter = this->vars.find(key);
auto src_iter = this->vars.find(key);
if (src_iter == this->vars.end()) {
/* The value has been deleted. */
vars_to_acquire.erase(key);

View file

@ -93,8 +93,8 @@ static void safe_launch_process(process_t *p, const char *actual_cmd, const char
int err;
// This function never returns, so we take certain liberties with constness.
char *const *envv = const_cast<char *const *>(cenvv);
char *const *argv = const_cast<char *const *>(cargv);
const auto envv = const_cast<char *const *>(cenvv);
const auto argv = const_cast<char *const *>(cargv);
execve(actual_cmd, argv, envv);
err = errno;
@ -1062,8 +1062,7 @@ static void populate_subshell_output(wcstring_list_t *lst, const io_buffer_t &bu
const char *cursor = begin;
while (cursor < end) {
// Look for the next separator.
const char *stop =
static_cast<const char *>(std::memchr(cursor, '\n', end - cursor));
auto stop = static_cast<const char *>(std::memchr(cursor, '\n', end - cursor));
const bool hit_separator = (stop != nullptr);
if (!hit_separator) {
// If it's not found, just use the end.

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 = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (len + 1)));
auto out = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (len + 1)));
if (out == nullptr) {
return nullptr;
}
@ -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 = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (c + 1)));
auto res = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (c + 1)));
if (res == nullptr) {
return nullptr;
}

View file

@ -336,12 +336,12 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
auto cats = get_flog_categories();
// Compute width of longest name.
int name_width = 0;
for (const auto *cat : cats) {
for (auto cat : cats) {
name_width = std::max(name_width, static_cast<int>(wcslen(cat->name)));
}
// A little extra space.
name_width += 2;
for (const auto *cat : cats) {
for (auto cat : cats) {
// Negating the name width left-justifies.
printf("%*ls %ls\n", -name_width, cat->name, _(cat->description));
}

View file

@ -810,8 +810,8 @@ static void test_fd_monitor() {
item_oneshot.always_exit = true;
{
fd_monitor_t monitor;
for (auto *item : {&item_never, &item_hugetimeout, &item0_timeout, &item42_timeout,
&item42_nottimeout, &item42_thenclose, &item_oneshot}) {
for (auto item : {&item_never, &item_hugetimeout, &item0_timeout, &item42_timeout,
&item42_nottimeout, &item42_thenclose, &item_oneshot}) {
monitor.add(std::move(item->item));
}
item42_timeout.write42();

View file

@ -80,7 +80,7 @@ static owning_lock<function_set_t> function_set;
bool function_set_t::allow_autoload(const wcstring &name) const {
// Prohibit autoloading if we have a non-autoload (explicit) function, or if the function is
// tombstoned.
const auto *info = get_info(name);
auto info = get_info(name);
bool has_explicit_func = info && !info->is_autoload;
bool is_tombstoned = autoload_tombstones.count(name) > 0;
return !has_explicit_func && !is_tombstoned;
@ -175,7 +175,7 @@ void function_add(wcstring name, wcstring description, function_properties_ref_t
std::shared_ptr<const function_properties_t> function_get_properties(const wcstring &name) {
if (parser_keywords_is_reserved(name)) return nullptr;
auto funcset = function_set.acquire();
if (const auto *info = funcset->get_info(name)) {
if (auto info = funcset->get_info(name)) {
return info->props;
}
return nullptr;

View file

@ -466,8 +466,7 @@ void history_impl_t::set_valid_file_paths(const wcstring_list_t &valid_file_path
}
// Look for an item with the given identifier. It is likely to be at the end of new_items.
for (history_item_list_t::reverse_iterator iter = new_items.rbegin(); iter != new_items.rend();
++iter) {
for (auto iter = new_items.rbegin(); iter != new_items.rend(); ++iter) {
if (iter->identifier == ident) { // found it
iter->required_paths = valid_file_paths;
break;
@ -603,7 +602,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 = static_cast<size_t>(-1);
const auto max_index = static_cast<size_t>(-1);
if (current_index_ == max_index) return false;

View file

@ -29,7 +29,7 @@ static bool should_mmap(int fd) {
// Return true on success, false on failure.
static bool read_from_fd(int fd, void *address, size_t len) {
size_t remaining = len;
char *ptr = static_cast<char *>(address);
auto ptr = static_cast<char *>(address);
while (remaining > 0) {
ssize_t amt = read(fd, ptr, remaining);
if (amt < 0) {
@ -162,7 +162,7 @@ history_item_t history_file_contents_t::decode_item(size_t offset) const {
}
maybe_t<size_t> history_file_contents_t::offset_of_next_item(size_t *cursor, time_t cutoff) {
size_t offset = size_t(-1);
auto offset = size_t(-1);
switch (this->type()) {
case history_type_fish_2_0:
offset = offset_of_next_item_fish_2_0(*this, cursor, cutoff);
@ -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 = static_cast<const char *>(std::memchr(start, '\n', len - cursor));
auto a_newline = static_cast<const char *>(std::memchr(start, '\n', len - cursor));
if (a_newline != nullptr) { // we found a newline
result.assign(start, a_newline - start);
// Return the amount to advance the cursor; skip over the newline.
@ -342,7 +342,7 @@ static const char *next_line(const char *start, const char *end) {
static size_t offset_of_next_item_fish_2_0(const history_file_contents_t &contents,
size_t *inout_cursor, time_t cutoff_timestamp) {
size_t cursor = *inout_cursor;
size_t result = size_t(-1);
auto result = size_t(-1);
const size_t length = contents.length();
const char *const begin = contents.begin();
const char *const end = contents.end();
@ -350,8 +350,7 @@ 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 =
static_cast<const char *>(std::memchr(line_start, '\n', length - cursor));
auto a_newline = static_cast<const char *>(std::memchr(line_start, '\n', length - cursor));
if (a_newline == nullptr) break;
// Advance the cursor past this line. +1 is for the newline.
@ -509,7 +508,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 = static_cast<time_t>(fish_wcstol(time_string));
auto tm = static_cast<time_t>(fish_wcstol(time_string));
if (!errno && tm >= 0) {
timestamp = tm;
}

View file

@ -31,7 +31,7 @@
/// Provide the fd monitor used for background fillthread operations.
static fd_monitor_t &fd_monitor() {
// Deliberately leaked to avoid shutdown dtors.
static fd_monitor_t *fdm = new fd_monitor_t();
static auto fdm = new fd_monitor_t();
return *fdm;
}
@ -202,7 +202,7 @@ io_buffer_t::~io_buffer_t() {
void io_chain_t::remove(const shared_ptr<const io_data_t> &element) {
// See if you can guess why std::find doesn't work here.
for (io_chain_t::iterator iter = this->begin(); iter != this->end(); ++iter) {
for (auto iter = this->begin(); iter != this->end(); ++iter) {
if (*iter == element) {
this->erase(iter);
break;

View file

@ -466,7 +466,7 @@ using void_func_t = std::function<void(void)>;
static void *func_invoker(void *param) {
// Acquire a thread id for this thread.
(void)thread_id();
void_func_t *vf = static_cast<void_func_t *>(param);
auto vf = static_cast<void_func_t *>(param);
(*vf)();
delete vf;
return nullptr;
@ -474,7 +474,7 @@ static void *func_invoker(void *param) {
bool make_detached_pthread(void_func_t &&func) {
// Copy the function into a heap allocation.
void_func_t *vf = new void_func_t(std::move(func));
auto vf = new void_func_t(std::move(func));
if (make_detached_pthread(func_invoker, vf)) {
return true;
}

View file

@ -22,13 +22,13 @@ static CharT **make_null_terminated_array_helper(
}
// Now allocate their sum.
unsigned char *base =
auto base =
static_cast<unsigned char *>(malloc(pointers_allocation_len + strings_allocation_len));
if (!base) return nullptr;
// Divvy it up into the pointers and strings.
CharT **pointers = reinterpret_cast<CharT **>(base);
CharT *strings = reinterpret_cast<CharT *>(base + pointers_allocation_len);
auto pointers = reinterpret_cast<CharT **>(base);
auto strings = reinterpret_cast<CharT *>(base + pointers_allocation_len);
// Start copying.
for (size_t i = 0; i < count; i++) {

View file

@ -64,7 +64,7 @@ class null_terminated_array_t {
/// Convert from a null terminated list to a vector of strings.
static string_list_t to_list(const CharT *const *arr) {
string_list_t result;
for (const auto *cursor = arr; cursor && *cursor; cursor++) {
for (auto cursor = arr; cursor && *cursor; cursor++) {
result.push_back(*cursor);
}
return result;

View file

@ -84,7 +84,7 @@ static size_t print_max(const wcstring &str, highlight_spec_t color, size_t max,
// skip non-printable characters
continue;
}
size_t width_c = size_t(iwidth_c);
auto width_c = size_t(iwidth_c);
if (width_c > remaining) break;
@ -139,7 +139,7 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s
auto modify_role = [=](highlight_role_t role) -> highlight_role_t {
using uint_t = typename std::underlying_type<highlight_role_t>::type;
uint_t base = static_cast<uint_t>(role);
auto base = static_cast<uint_t>(role);
if (selected) {
base += static_cast<uint_t>(highlight_role_t::pager_selected_background) -
static_cast<uint_t>(highlight_role_t::pager_background);

View file

@ -453,7 +453,7 @@ class parse_ll_t {
// it's lowest on the stack)
const size_t child_start_big = nodes.size();
assert(child_start_big < NODE_OFFSET_INVALID);
node_offset_t child_start = static_cast<node_offset_t>(child_start_big);
auto child_start = static_cast<node_offset_t>(child_start_big);
// To avoid constructing multiple nodes, we make a single one that we modify.
parse_node_t representative_child(token_type_invalid);
@ -728,7 +728,7 @@ void parse_ll_t::parse_error_unexpected_token(const wchar_t *expected, parse_tok
void parse_ll_t::reset_symbols(enum parse_token_type_t goal) {
// Add a new goal node, and then reset our symbol list to point at it.
node_offset_t where = static_cast<node_offset_t>(nodes.size());
auto where = static_cast<node_offset_t>(nodes.size());
nodes.push_back(parse_node_t(goal));
symbol_stack.clear();

View file

@ -96,7 +96,7 @@ void proc_init() { signal_set_handlers_once(false); }
// Basic thread safe sorted vector of job IDs in use.
// This is deliberately leaked to avoid dtor ordering issues - see #6539.
static auto *const locked_consumed_job_ids = new owning_lock<std::vector<job_id_t>>();
static const auto locked_consumed_job_ids = new owning_lock<std::vector<job_id_t>>();
job_id_t acquire_job_id() {
auto consumed_job_ids = locked_consumed_job_ids->acquire();

View file

@ -148,13 +148,13 @@ operation_context_t get_bg_context(const std::shared_ptr<environment_t> &env,
/// These are deliberately leaked to avoid shutdown dtor registration.
static debounce_t &debounce_autosuggestions() {
const long kAutosuggetTimeoutMs = 500;
static debounce_t *res = new debounce_t(kAutosuggetTimeoutMs);
static auto res = new debounce_t(kAutosuggetTimeoutMs);
return *res;
}
static debounce_t &debounce_highlighting() {
const long kHighlightTimeoutMs = 500;
static debounce_t *res = new debounce_t(kHighlightTimeoutMs);
static auto res = new debounce_t(kHighlightTimeoutMs);
return *res;
}
@ -549,7 +549,7 @@ class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
}
editable_line_t *active_edit_line() {
const auto *cthis = this;
auto cthis = reinterpret_cast<const reader_data_t *>(this);
return const_cast<editable_line_t *>(cthis->active_edit_line());
}

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 = static_cast<te_expr *>(malloc(size));
auto 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,7 +142,7 @@ 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 = static_cast<unsigned int>(a);
auto 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;
@ -448,7 +448,7 @@ static te_expr *factor(state *s) {
while (s->type == TOK_INFIX &&
(s->function == reinterpret_cast<const void *>(static_cast<te_fun2>(pow)))) {
te_fun2 t = (te_fun2)s->function;
auto t = (te_fun2)s->function;
next_token(s);
if (insertion) {
@ -475,7 +475,7 @@ static te_expr *term(state *s) {
(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;
auto t = (te_fun2)s->function;
next_token(s);
ret = NEW_EXPR(TE_FUNCTION2, ret, factor(s));
ret->function = reinterpret_cast<const void *>(t);
@ -489,7 +489,7 @@ static te_expr *expr(state *s) {
te_expr *ret = term(s);
while (s->type == TOK_INFIX && (s->function == add || s->function == sub)) {
te_fun2 t = (te_fun2)s->function;
auto t = (te_fun2)s->function;
next_token(s);
ret = NEW_EXPR(TE_FUNCTION2, ret, term(s));
ret->function = reinterpret_cast<const void *>(t);

View file

@ -67,7 +67,7 @@ bool wchar_to_utf8_string(const std::wstring &str, std::string *result) {
const wchar_t *input = str.c_str();
size_t outlen = wchar_to_utf8(input, inlen, nullptr, 0, 0);
if (outlen > 0) {
char *tmp = new char[outlen];
auto tmp = new char[outlen];
size_t outlen2 = wchar_to_utf8(input, inlen, tmp, outlen, 0);
if (outlen2 > 0) {
result->assign(tmp, outlen2);
@ -110,7 +110,7 @@ size_t wchar_to_utf8(const wchar_t *in, size_t insize, char *out, size_t outsize
} else {
// Allocate a temporary buffer to hold the input the std::copy performs the size conversion.
// Note: insize may be 0.
utf8_wchar_t *tmp_input = new utf8_wchar_t[insize];
auto tmp_input = new utf8_wchar_t[insize];
if (!safe_copy_wchar_to_utf8_wchar(in, tmp_input, insize)) {
// Our utf8_wchar_t is UCS-16 and there was an astral character.
result = 0;