id
stringlengths
27
29
content
stringlengths
226
3.24k
codereview_new_cpp_data_7132
TEST(sycl, raw_sycl_interop) { Kokkos::Experimental::SYCL default_space; sycl::context default_context = default_space.sycl_queue().get_context(); - sycl::default_selector device_selector; - sycl::queue queue(default_context, device_selector); constexpr int n = 100; int* p = sycl::malloc_device<int>(n, queue); { Presumably, this is just a new available syntax, not a deprecation. Please propose these changes (prefer `sycl::default_selector_v `) in a separate PR. TEST(sycl, raw_sycl_interop) { Kokkos::Experimental::SYCL default_space; sycl::context default_context = default_space.sycl_queue().get_context(); + sycl::queue queue(default_context, sycl::default_selector_v); constexpr int n = 100; int* p = sycl::malloc_device<int>(n, queue); {
codereview_new_cpp_data_7133
int SYCL::concurrency() { return Impl::SYCLInternal::singleton().m_maxConcurrency; } #else -int SYCL::concurrency() const { - return Impl::SYCLInternal::singleton().m_maxConcurrency; -} #endif const char* SYCL::name() { return "SYCL"; } why not return `m_space_instance->m_maxConcurrency`? int SYCL::concurrency() { return Impl::SYCLInternal::singleton().m_maxConcurrency; } #else +int SYCL::concurrency() const { return m_space_instance->m_maxConcurrency; } #endif const char* SYCL::name() { return "SYCL"; }
codereview_new_cpp_data_7134
void OpenMPInternal::initialize(int thread_count) { } // Check for over-subscription - auto const mpi_local_size = []() { - auto ranks = mpi_ranks_per_node(); - if (ranks < 0) return 1; - return ranks; - }(); if (Kokkos::show_warnings() && (mpi_local_size * long(thread_count) > Impl::processors_per_node())) { std::cerr << "Kokkos::OpenMP::initialize WARNING: You are likely " Why the unusual arrangement of calling a one-off lambda here and in Threads? void OpenMPInternal::initialize(int thread_count) { } // Check for over-subscription + auto const reported_ranks = mpi_ranks_per_node(); + auto const mpi_local_size = reported_ranks < 0 ? 1 : reported_ranks; if (Kokkos::show_warnings() && (mpi_local_size * long(thread_count) > Impl::processors_per_node())) { std::cerr << "Kokkos::OpenMP::initialize WARNING: You are likely "
codereview_new_cpp_data_7135
void OpenMPInternal::initialize(int thread_count) { } // Check for over-subscription - auto const mpi_local_size = []() { - auto ranks = mpi_ranks_per_node(); - if (ranks < 0) return 1; - return ranks; - }(); if (Kokkos::show_warnings() && (mpi_local_size * long(thread_count) > Impl::processors_per_node())) { std::cerr << "Kokkos::OpenMP::initialize WARNING: You are likely " ```suggestion const auto reported_ranks = mpi_ranks_per_node(); const auto mpi_local_size = reported_ranks < 0 ? 1 : reported_ranks; ``` This seems much less roundabout If C++ were a more expression-oriented language, this would of course be less troublesome. I'm just concerned about generated code size and representation, if the compiler isn't aggressive about inlining constructs like the lambda. void OpenMPInternal::initialize(int thread_count) { } // Check for over-subscription + auto const reported_ranks = mpi_ranks_per_node(); + auto const mpi_local_size = reported_ranks < 0 ? 1 : reported_ranks; if (Kokkos::show_warnings() && (mpi_local_size * long(thread_count) > Impl::processors_per_node())) { std::cerr << "Kokkos::OpenMP::initialize WARNING: You are likely "
codereview_new_cpp_data_7136
BENCHMARK(Atomic_ContentiousMinReplacements<double>) ->Arg(LENGTH / 5) ->UseManualTime() ->Iterations(10); -/////////////////////////////////////////////////////////////////////// - -int main(int argc, char* argv[]) { - Kokkos::initialize(argc, argv); - benchmark::Initialize(&argc, argv); - benchmark::SetDefaultTimeUnit(benchmark::kSecond); - KokkosBenchmark::add_benchmark_context(true); - - (void)Test::command_line_num_args(argc); - (void)Test::command_line_arg(0, argv); - - benchmark::RunSpecifiedBenchmarks(); - - benchmark::Shutdown(); - Kokkos::finalize(); - return 0; -} TODO: consider using `BenchmarkMain.cpp`. BENCHMARK(Atomic_ContentiousMinReplacements<double>) ->Arg(LENGTH / 5) ->UseManualTime() ->Iterations(10);
codereview_new_cpp_data_7137
TEST(defaultdevicetype, shared_space) { // GET PAGE MIGRATING TIMINGS DATA std::vector<decltype(deviceLocalTimings)> deviceSharedTimings{}; - std::vector<decltype(deviceLocalTimings)> hostSharedTimings{}; for (unsigned i = 0; i < numDeviceHostCycles; ++i) { // GET RESULTS DEVICE deviceSharedTimings.push_back( I know they are the same type but I'd prefer ```suggestion std::vector<decltype(hostLocalTimings)> hostSharedTimings{}; ``` TEST(defaultdevicetype, shared_space) { // GET PAGE MIGRATING TIMINGS DATA std::vector<decltype(deviceLocalTimings)> deviceSharedTimings{}; + std::vector<decltype(hostLocalTimings)> hostSharedTimings{}; for (unsigned i = 0; i < numDeviceHostCycles; ++i) { // GET RESULTS DEVICE deviceSharedTimings.push_back(
codereview_new_cpp_data_7138
int get_device_count() { return acc_get_num_devices( Kokkos::Experimental::Impl::OpenACC_Traits::dev_type); #elif defined(KOKKOS_ENABLE_OPENMPTARGET) - return Kokkos::Experimental::OpenMPTarget::detect_device_count(); #else Kokkos::abort("implementation bug"); return -1; If this is the only place where this function is used, I would prefer just inlining it. int get_device_count() { return acc_get_num_devices( Kokkos::Experimental::Impl::OpenACC_Traits::dev_type); #elif defined(KOKKOS_ENABLE_OPENMPTARGET) + return omp_get_num_devices(); #else Kokkos::abort("implementation bug"); return -1;
codereview_new_cpp_data_7139
TEST(std_algorithms_nonmod_seq_ops, adjacent_find) { #if defined(KOKKOS_ENABLE_CUDA) && \ defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC if constexpr (std::is_same_v<exespace, Kokkos::Cuda>) { - GTEST_SKIP() << "FIXME please"; } #endif run_all_scenarios<DynamicTag, int>(); Wrong result? Compiler error? Please comment. TEST(std_algorithms_nonmod_seq_ops, adjacent_find) { #if defined(KOKKOS_ENABLE_CUDA) && \ defined(KOKKOS_COMPILER_NVHPC) // FIXME_NVHPC if constexpr (std::is_same_v<exespace, Kokkos::Cuda>) { + GTEST_SKIP() << "FIXME wrong result"; } #endif run_all_scenarios<DynamicTag, int>();
codereview_new_cpp_data_7140
int HIP::impl_is_initialized() { void HIP::impl_initialize(InitializationSettings const& settings) { const int hip_device_id = Impl::get_gpu(settings); - // Need at least a GPU device - int hipDevCount; - KOKKOS_IMPL_HIP_SAFE_CALL(hipGetDeviceCount(&hipDevCount)); - Impl::HIPInternal::m_hipDev = hip_device_id; KOKKOS_IMPL_HIP_SAFE_CALL( hipGetDeviceProperties(&Impl::HIPInternal::m_deviceProp, hip_device_id)); Seeing that `HIP::detect_device_count()` now does the same thing as this line, ```suggestion int hipDevCount = HIP::detect_device_count(); ``` int HIP::impl_is_initialized() { void HIP::impl_initialize(InitializationSettings const& settings) { const int hip_device_id = Impl::get_gpu(settings); Impl::HIPInternal::m_hipDev = hip_device_id; KOKKOS_IMPL_HIP_SAFE_CALL( hipGetDeviceProperties(&Impl::HIPInternal::m_deviceProp, hip_device_id));
codereview_new_cpp_data_7141
void cuda_internal_error_abort(cudaError e, const char *name, const char *file, if (file) { out << " " << file << ":" << line; } - // Call Kokkos::Impl::host_abort instead of Kokkos::abort to avoid a warning - // about Kokkos::abort returning in some cases. - host_abort(out.str().c_str()); } //---------------------------------------------------------------------------- I am not sure about that one. I don't like spreading use of internal details if we can avoid. This would be the first use of `Impl::host_abort` in the code base besides the definition of `Kokkos::abort`. What other option do we have? void cuda_internal_error_abort(cudaError e, const char *name, const char *file, if (file) { out << " " << file << ":" << line; } + abort(out.str().c_str()); } //----------------------------------------------------------------------------
codereview_new_cpp_data_7962
void AdvancedView::update(Cluster cluster) startButton->setText(getStartLabel(isRunning)); QString startToolTip = ""; if (isRunning) { - startToolTip = "Restart the Kubernetes API"; } startButton->setToolTip(startToolTip); } Restarts the already started minikube that might refresh the config void AdvancedView::update(Cluster cluster) startButton->setText(getStartLabel(isRunning)); QString startToolTip = ""; if (isRunning) { + startToolTip = "Restart an already running minikube instance to pickup config changes."; } startButton->setToolTip(startToolTip); }
codereview_new_cpp_data_7979
static ut64 shifted_imm64(Instruction *insn, int n, int sz) { // #define VEC64(n) insn->detail->arm64.operands[n].vess #define VEC64_APPEND(sb, n, i) vector64_append (sb, insn, n, i) -#define VEC64_MASK(sh, sz) (bitmask_by_width[63]^(bitmask_by_width[sz-1]<<sh)) static void vector64_append(RStrBuf *sb, Instruction *insn, int n, int i) { InstructionOperand op = INSOP64 (n); ```suggestion #define VEC64_MASK(sh, sz) (bitmask_by_width[63] ^ (bitmask_by_width[sz - 1] << sh)) ``` static ut64 shifted_imm64(Instruction *insn, int n, int sz) { // #define VEC64(n) insn->detail->arm64.operands[n].vess #define VEC64_APPEND(sb, n, i) vector64_append (sb, insn, n, i) +#define VEC64_MASK(sh, sz) (bitmask_by_width[63] ^ (bitmask_by_width[sz - 1] << sh)) static void vector64_append(RStrBuf *sb, Instruction *insn, int n, int i) { InstructionOperand op = INSOP64 (n);
codereview_new_cpp_data_7980
R_IPI int wasm_asm(const char *str, ut8 *buf, int buf_len) { } } // TODO: parse immediates - return len? len: -1; } // disassemble an instruction from the given buffer. ```suggestion return len > 0? len: -1; ``` R_IPI int wasm_asm(const char *str, ut8 *buf, int buf_len) { } } // TODO: parse immediates + return len > 0? len: -1; } // disassemble an instruction from the given buffer.
codereview_new_cpp_data_7981
ut64 Elf_(r_bin_elf_get_entry_offset)(ELFOBJ *bin) { if (entry) { return Elf_(r_bin_elf_v2p) (bin, entry); } - return get_entry_offset_from_shdr(bin); } static ut64 getmainsymbol(ELFOBJ *bin) { ```suggestion return get_entry_offset_from_shdr (bin); ``` ut64 Elf_(r_bin_elf_get_entry_offset)(ELFOBJ *bin) { if (entry) { return Elf_(r_bin_elf_v2p) (bin, entry); } + return get_entry_offset_from_shdr (bin); } static ut64 getmainsymbol(ELFOBJ *bin) {
codereview_new_cpp_data_7982
R_API void r_core_loadlibs_init(RCore *core) { DF (BIN, "bin plugins", bin); DF (EGG, "egg plugins", egg); DF (FS, "fs plugins", fs); - DF (ARCH, "archplugins", arch); core->times->loadlibs_init_time = r_time_now_mono () - prev; } ```suggestion DF (ARCH, "arch plugins", arch); ``` R_API void r_core_loadlibs_init(RCore *core) { DF (BIN, "bin plugins", bin); DF (EGG, "egg plugins", egg); DF (FS, "fs plugins", fs); + DF (ARCH, "arch plugins", arch); core->times->loadlibs_init_time = r_time_now_mono () - prev; }
codereview_new_cpp_data_7983
R_API bool r_project_rename(RProject *p, const char *newname) { free (p->name); p->path = new_prjdir; p->name = new_name; - rvc_close(p->rvc, true); p->rvc = NULL; return true; } ```suggestion rvc_close (p->rvc, true); ``` R_API bool r_project_rename(RProject *p, const char *newname) { free (p->name); p->path = new_prjdir; p->name = new_name; + rvc_close (p->rvc, true); p->rvc = NULL; return true; }
codereview_new_cpp_data_7984
R_API bool r_core_project_save(RCore *core, const char *prj_name) { free (cwd); } // LEAK : not always in heap free (prj_name); core->prj->path = prj_dir; if (scr_null) { r_config_set_b (core->config, "scr.null", true); maybe good to free (core->prj->path) before overwriting the field? R_API bool r_core_project_save(RCore *core, const char *prj_name) { free (cwd); } // LEAK : not always in heap free (prj_name); + free(core->prj->path); core->prj->path = prj_dir; if (scr_null) { r_config_set_b (core->config, "scr.null", true);
codereview_new_cpp_data_7985
R_API bool r_project_rename(RProject *p, const char *newname) { return true; } } return false; } newprjdir will leak if newname is null R_API bool r_project_rename(RProject *p, const char *newname) { return true; } } + free (newprjdir); return false; }
codereview_new_cpp_data_7986
R_API bool r_vc_git_commit(Rvc *vc, const char *_message, const char *author, co if (epath) { char *emsg = r_str_escape (message); if (emsg) { - int res = r_sys_cmdf ("git -C %s commit -m \"%s\" --author \"%s <%s@localhost>\"", epath, emsg, escauth, escauth); free (escauth); free (message); ```suggestion int res = r_sys_cmdf ("git -C \"%s\" commit -m \"%s\" --author \"%s <%s@localhost>\"", ``` R_API bool r_vc_git_commit(Rvc *vc, const char *_message, const char *author, co if (epath) { char *emsg = r_str_escape (message); if (emsg) { + int res = r_sys_cmdf ("git -C \"%s\" commit -m \"%s\" --author \"%s <%s@localhost>\"", epath, emsg, escauth, escauth); free (escauth); free (message);
codereview_new_cpp_data_7987
R_API bool r2r_check_jq_available(void) { const char *invalid_json = "this is not json lol"; R2RSubprocess *proc = r2r_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); if (!proc) { - R_LOG_ERROR ("Cnnot start subprocess"); return false; } r2r_subprocess_stdin_write (proc, (const ut8 *)invalid_json, strlen (invalid_json)); ```suggestion R_LOG_ERROR ("Cannot start subprocess"); ``` R_API bool r2r_check_jq_available(void) { const char *invalid_json = "this is not json lol"; R2RSubprocess *proc = r2r_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); if (!proc) { + R_LOG_ERROR ("Cannot start subprocess"); return false; } r2r_subprocess_stdin_write (proc, (const ut8 *)invalid_json, strlen (invalid_json));
codereview_new_cpp_data_7988
R_API int r_main_ravc2(int argc, const char **argv) { } else if (!strcmp (action, "checkout") && opt.argc > 2) { save = rvc_git_checkout (rvc, opt.argv[opt.ind + 1]); } else if (!strcmp (action, "status")) { - char *current_branch = r_vc_git_current_branch (rvc); if (current_branch) { printf ("Branch: %s\n", current_branch); RList *uncommitted = rvc->p->get_uncommitted (rvc); shouldnt Rvc.currentBranch() call Rvc.gitCurrentBranch() internally? maybe the bug should be somewhere else R_API int r_main_ravc2(int argc, const char **argv) { } else if (!strcmp (action, "checkout") && opt.argc > 2) { save = rvc_git_checkout (rvc, opt.argv[opt.ind + 1]); } else if (!strcmp (action, "status")) { + char *current_branch = rvc->p->current_branch (rvc); if (current_branch) { printf ("Branch: %s\n", current_branch); RList *uncommitted = rvc->p->get_uncommitted (rvc);
codereview_new_cpp_data_7989
R_API RList *r_type_get_enum(Sdb *TDB, const char *name) { } R_API void r_type_enum_free(RTypeEnum *member) { - free (member->name); - free (member->val); - free (member); } R_API char *r_type_enum_member(Sdb *TDB, const char *name, const char *member, ut64 val) { All free methods must accept null. Add an if here R_API RList *r_type_get_enum(Sdb *TDB, const char *name) { } R_API void r_type_enum_free(RTypeEnum *member) { + if (member) { + free (member->name); + free (member->val); + free (member); + } } R_API char *r_type_enum_member(Sdb *TDB, const char *name, const char *member, ut64 val) {
codereview_new_cpp_data_7990
RList *MACH0_(parse_classes)(RBinFile *bf, objc_cache_opt_info *oi) { int i, amount = swift5_types_size / 4; int res = r_buf_read_at (bf->buf, swift5_types_addr, (ut8*)words, aligned_size); // TODO check for return if (res >= aligned_size) { - for (i = 0; i + 4 < amount; i++) { st32 word = r_read_le32 (&words[i]); ut64 type_address = swift5_types_addr + (i * 4) + word; SwiftType st = parse_type_entry (bf, type_address); ```suggestion for (i = 0; i < amount; i++) { ``` RList *MACH0_(parse_classes)(RBinFile *bf, objc_cache_opt_info *oi) { int i, amount = swift5_types_size / 4; int res = r_buf_read_at (bf->buf, swift5_types_addr, (ut8*)words, aligned_size); // TODO check for return if (res >= aligned_size) { + for (i = 0; i < amount; i++) { st32 word = r_read_le32 (&words[i]); ut64 type_address = swift5_types_addr + (i * 4) + word; SwiftType st = parse_type_entry (bf, type_address);
codereview_new_cpp_data_7991
static inline int l_num_to_bytes(ut64 n, bool sign) { test = -test; flip = true; } - st64 last; while (test) { last = test; test = test >> 8; ```suggestion st64 last = 0; ``` static inline int l_num_to_bytes(ut64 n, bool sign) { test = -test; flip = true; } + st64 last = 0; while (test) { last = test; test = test >> 8;
codereview_new_cpp_data_7992
R_API bool r_core_project_is_dirty(RCore *core) { } R_API void r_core_project_undirty(RCore *core) { core->config->is_dirty = false; core->anal->is_dirty = false; core->flags->is_dirty = false; } dont remove those R_API bool r_core_project_is_dirty(RCore *core) { } R_API void r_core_project_undirty(RCore *core) { + R_CRITICAL_ENTER (core); core->config->is_dirty = false; core->anal->is_dirty = false; core->flags->is_dirty = false; + R_CRITICAL_LEAVE (core); }
codereview_new_cpp_data_7993
R_API bool r_core_project_is_dirty(RCore *core) { } R_API void r_core_project_undirty(RCore *core) { core->config->is_dirty = false; core->anal->is_dirty = false; core->flags->is_dirty = false; } ```suggestion R_CRITICAL_ENTER (core); core->config->is_dirty = false; ``` R_API bool r_core_project_is_dirty(RCore *core) { } R_API void r_core_project_undirty(RCore *core) { + R_CRITICAL_ENTER (core); core->config->is_dirty = false; core->anal->is_dirty = false; core->flags->is_dirty = false; + R_CRITICAL_LEAVE (core); }
codereview_new_cpp_data_7994
R_API bool r_core_project_is_dirty(RCore *core) { } R_API void r_core_project_undirty(RCore *core) { core->config->is_dirty = false; core->anal->is_dirty = false; core->flags->is_dirty = false; } ```suggestion core->flags->is_dirty = false; R_CRITICAL_LEAVE (core); ``` R_API bool r_core_project_is_dirty(RCore *core) { } R_API void r_core_project_undirty(RCore *core) { + R_CRITICAL_ENTER (core); core->config->is_dirty = false; core->anal->is_dirty = false; core->flags->is_dirty = false; + R_CRITICAL_LEAVE (core); }
codereview_new_cpp_data_7995
R_API int r_main_ravc2(int argc, const char **argv) { printf ("Branch: %s\n", current_branch); RList *uncommitted = rvc->get_uncommitted (rvc); if (r_list_empty (uncommitted)) { - printf ("All files are committed\n"); } else { - printf ("The following files were NOT committed:\n"); RListIter *iter; char *file; r_list_foreach (uncommitted, iter, file) { ```suggestion R_LOG_INFO ("The following files were NOT committed"); ``` R_API int r_main_ravc2(int argc, const char **argv) { printf ("Branch: %s\n", current_branch); RList *uncommitted = rvc->get_uncommitted (rvc); if (r_list_empty (uncommitted)) { + R_LOG_INFO ("All files are committed"); } else { + R_LOG_INFO ("The following files were NOT committed"); RListIter *iter; char *file; r_list_foreach (uncommitted, iter, file) {
codereview_new_cpp_data_7996
R_API void r_core_anal_autoname_all_golang_fcns(RCore *core) { if (num_syms) { R_LOG_INFO ("Found %d symbols and saved them at sym.go.*", num_syms); } else { - R_LOG_ERROR ("Found no symbols."); } } ```suggestion R_LOG_ERROR ("Found no symbols"); ``` R_API void r_core_anal_autoname_all_golang_fcns(RCore *core) { if (num_syms) { R_LOG_INFO ("Found %d symbols and saved them at sym.go.*", num_syms); } else { + R_LOG_ERROR ("Found no symbols"); } }
codereview_new_cpp_data_7997
RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut RCoreSymCacheElementSegment *seg = &result->segments[i]; seg->paddr = seg->vaddr = r_read_le64 (cursor); cursor += 8; - if (cursor + 8 >= end) { break; } seg->size = seg->vsize = r_read_le64 (cursor); ```suggestion if (cursor + 8 > end) { ``` RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut RCoreSymCacheElementSegment *seg = &result->segments[i]; seg->paddr = seg->vaddr = r_read_le64 (cursor); cursor += 8; + if (cursor + 8 > end) { break; } seg->size = seg->vsize = r_read_le64 (cursor);
codereview_new_cpp_data_7998
RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut RCoreSymCacheElementSegment *seg = &result->segments[i]; seg->paddr = seg->vaddr = r_read_le64 (cursor); cursor += 8; - if (cursor + 8 >= end) { break; } seg->size = seg->vsize = r_read_le64 (cursor); ```suggestion if (cursor + 16 > end) { ``` RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut RCoreSymCacheElementSegment *seg = &result->segments[i]; seg->paddr = seg->vaddr = r_read_le64 (cursor); cursor += 8; + if (cursor + 8 > end) { break; } seg->size = seg->vsize = r_read_le64 (cursor);
codereview_new_cpp_data_7999
RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut return NULL; } if (hdr->version != 1 && hdr->version != 7) { - eprintf ("Unsupported CoreSymbolication cache version (%d)\n", hdr->version); goto beach; } if (hdr->size == 0 || hdr->size > r_buf_size (buf) - off) { - eprintf ("Corrupted CoreSymbolication header: size out of bounds (0x%x)\n", hdr->size); goto beach; } result = R_NEW0 (RCoreSymCacheElement); use R_LOG_ERROR instead of eprintf ```suggestion R_LOG_ERROR ("Unsupported CoreSymbolication cache version (%d)", hdr->version); ``` RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut return NULL; } if (hdr->version != 1 && hdr->version != 7) { + R_LOG_ERROR ("Unsupported CoreSymbolication cache version (%d)", hdr->version); goto beach; } if (hdr->size == 0 || hdr->size > r_buf_size (buf) - off) { + R_LOG_ERROR ("Corrupted CoreSymbolication header: size out of bounds (0x%x)", hdr->size); goto beach; } result = R_NEW0 (RCoreSymCacheElement);
codereview_new_cpp_data_8000
static void handle_var_stack_access(RAnalEsil *esil, ut64 addr, RAnalVarAccessTy if (addr >= spaddr && addr < ctx->initial_sp) { int stack_off = addr - ctx->initial_sp; // int stack_off = ctx->initial_sp - addr; // R2STACK - eprintf ("%x\n", stack_off); // eprintf (" (%llx) %llx = %d\n", ctx->initial_sp, addr, stack_off); RAnalVar *var = r_anal_function_get_var (ctx->fcn, R_ANAL_VAR_KIND_SPV, stack_off); if (!var) { FYI, this will spam console when running `aaa`. static void handle_var_stack_access(RAnalEsil *esil, ut64 addr, RAnalVarAccessTy if (addr >= spaddr && addr < ctx->initial_sp) { int stack_off = addr - ctx->initial_sp; // int stack_off = ctx->initial_sp - addr; // R2STACK // eprintf (" (%llx) %llx = %d\n", ctx->initial_sp, addr, stack_off); RAnalVar *var = r_anal_function_get_var (ctx->fcn, R_ANAL_VAR_KIND_SPV, stack_off); if (!var) {
codereview_new_cpp_data_8001
static inline void prevPrintFormat(RCore *core) { printFormat (core, -1); } -R_API bool r_core_visual_hud(RCore *core) { const char *c = r_config_get (core->config, "hud.path"); char *f = r_str_newf (R_JOIN_3_PATHS ("%s", R2_HUD, "main"), r_sys_prefix (NULL)); ```suggestion R_API int r_core_visual_hud(RCore *core) { ``` static inline void prevPrintFormat(RCore *core) { printFormat (core, -1); } +R_API int r_core_visual_hud(RCore *core) { const char *c = r_config_get (core->config, "hud.path"); char *f = r_str_newf (R_JOIN_3_PATHS ("%s", R2_HUD, "main"), r_sys_prefix (NULL));
codereview_new_cpp_data_8002
static inline int handle_opstring(RAnalOp *op, const ut8 *buf, int buflen) { return -1; } buf++; - buflen -= 1; // remove starting quote char *str = get_line (buf, buflen); if (str) { size_t len = strlen (str); ```suggestion buflen --; // remove starting quote ``` static inline int handle_opstring(RAnalOp *op, const ut8 *buf, int buflen) { return -1; } buf++; + buflen --; // remove starting quote char *str = get_line (buf, buflen); if (str) { size_t len = strlen (str);
codereview_new_cpp_data_8003
R_API void r_core_diff_show_json(RCore *c, RCore *c2) { const char *match; RListIter *iter; RAnalFunction *f; - PJ *pj = pj_new (); if (!pj) { return; Better use the corepj.new() if you have access to the core instance. This way the user have the ability to configure some options like indent, colors or how to represent 64bit numbers if they want R_API void r_core_diff_show_json(RCore *c, RCore *c2) { const char *match; RListIter *iter; RAnalFunction *f; + PJ *pj = core_pj_new (); if (!pj) { return;
codereview_new_cpp_data_8004
R_API void r_core_diff_show_json(RCore *c, RCore *c2) { fcns = r_anal_get_fcns (c->anal); if (r_list_empty (fcns)) { - R_LOG_INFO ("No functions found, try running with -A or load a project\n"); return; } This var is assigned twice R_API void r_core_diff_show_json(RCore *c, RCore *c2) { fcns = r_anal_get_fcns (c->anal); if (r_list_empty (fcns)) { + R_LOG_INFO ("No functions found, try running with -A or load a project"); return; }
codereview_new_cpp_data_8005
R_API void r_core_diff_show_json(RCore *c, RCore *c2) { fcns = r_anal_get_fcns (c->anal); if (r_list_empty (fcns)) { - R_LOG_INFO ("No functions found, try running with -A or load a project\n"); return; } ```suggestion R_LOG_INFO ("No functions found, try running with -A or load a project"); ``` R_API void r_core_diff_show_json(RCore *c, RCore *c2) { fcns = r_anal_get_fcns (c->anal); if (r_list_empty (fcns)) { + R_LOG_INFO ("No functions found, try running with -A or load a project"); return; }
codereview_new_cpp_data_8006
R_API void r_core_diff_show_json(RCore *c, RCore *c2) { fcns = r_anal_get_fcns (c->anal); if (r_list_empty (fcns)) { - R_LOG_INFO ("No functions found, try running with -A or load a project"); return; } ```suggestion R_LOG_ERROR ("No functions found, try running with -A or load a project"); ``` R_API void r_core_diff_show_json(RCore *c, RCore *c2) { fcns = r_anal_get_fcns (c->anal); if (r_list_empty (fcns)) { + R_LOG_ERROR ("No functions found, try running with -A or load a project"); return; }
codereview_new_cpp_data_8007
static char *pickle_mnemonics(RAnal *a, int id, bool json) { } if (id >= 0 && id < R_ARRAY_SIZE (op_name_map)) { return strdup (op_name_map[id].name); - } else if (id == -1) { size_t i; RStrBuf *buf = buf = r_strbuf_new (""); for (i = 0; i < R_ARRAY_SIZE (op_name_map); i++) { dont else after return static char *pickle_mnemonics(RAnal *a, int id, bool json) { } if (id >= 0 && id < R_ARRAY_SIZE (op_name_map)) { return strdup (op_name_map[id].name); + } + if (id == -1) { size_t i; RStrBuf *buf = buf = r_strbuf_new (""); for (i = 0; i < R_ARRAY_SIZE (op_name_map); i++) {
codereview_new_cpp_data_8008
static int pickle_opasm(RAnal *a, ut64 addr, const char *str, ut8 *outbuf, int o case OP_UNICODE: case OP_GET: case OP_PUT: - R_LOG_ERROR ("This assembler can't handle %s (op: 0x%02x) yet\n", opstr, op); wlen = -1; break; default: ```suggestion R_LOG_ERROR ("This assembler can't handle %s (op: 0x%02x) yet", opstr, op); ``` static int pickle_opasm(RAnal *a, ut64 addr, const char *str, ut8 *outbuf, int o case OP_UNICODE: case OP_GET: case OP_PUT: + R_LOG_ERROR ("This assembler can't handle %s (op: 0x%02x) yet", opstr, op); wlen = -1; break; default:
codereview_new_cpp_data_8009
R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step for (i = 0; i < size; i++) { cols = arr[i] > cols ? arr[i] : cols; } - int div = R_MAX(255 / (p->cols * 3), 1); cols /= div; for (i = 0; i < size; i++) { if (addr != UT64_MAX && step > 0) { ```suggestion int div = R_MAX (255 / (p->cols * 3), 1); ``` R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step for (i = 0; i < size; i++) { cols = arr[i] > cols ? arr[i] : cols; } + int div = R_MAX (255 / (p->cols * 3), 1); cols /= div; for (i = 0; i < size; i++) { if (addr != UT64_MAX && step > 0) {
codereview_new_cpp_data_8010
const char *file_fmttime(ut32 v, int local, char *pp, int *daylight) { } #endif /* HAVE_TM_ISDST */ #endif /* HAVE_DAYLIGHT */ - if (&daylight) { t += 3600; } #if __MINGW32__ ```suggestion if (*daylight) { ``` you need to access the contents with *, not the address of the reference const char *file_fmttime(ut32 v, int local, char *pp, int *daylight) { } #endif /* HAVE_TM_ISDST */ #endif /* HAVE_DAYLIGHT */ + if (*daylight) { t += 3600; } #if __MINGW32__
codereview_new_cpp_data_8011
static inline int handle_float(RAnalOp *op, const char *name, int sz, const ut8 static inline char *get_line(const ut8 *buf, int len) { // TODO: find end of large strings through RAnal->iob - char *str = (char *)malloc (len + 1); - strncpy (str, (char *)buf, len); - str[len + 1] = '\0'; - if (str) { char *n = strchr (str, '\n'); if (n) { Just use r_str_ndup static inline int handle_float(RAnalOp *op, const char *name, int sz, const ut8 static inline char *get_line(const ut8 *buf, int len) { // TODO: find end of large strings through RAnal->iob + char *str = r_str_ndup (buf, len); if (str) { char *n = strchr (str, '\n'); if (n) {
codereview_new_cpp_data_8012
static inline int handle_float(RAnalOp *op, const char *name, int sz, const ut8 static inline char *get_line(const ut8 *buf, int len) { // TODO: find end of large strings through RAnal->iob - char *str = (char *)malloc (len + 1); - strncpy (str, (char *)buf, len); - str[len + 1] = '\0'; - if (str) { char *n = strchr (str, '\n'); if (n) { this is an overflow. just use r_str_ndup static inline int handle_float(RAnalOp *op, const char *name, int sz, const ut8 static inline char *get_line(const ut8 *buf, int len) { // TODO: find end of large strings through RAnal->iob + char *str = r_str_ndup (buf, len); if (str) { char *n = strchr (str, '\n'); if (n) {
codereview_new_cpp_data_8013
static bool cb_asmpseudo(void *user, void *data) { RCore *core = (RCore *) user; RConfigNode *node = (RConfigNode *) data; core->rasm->pseudo = node->i_value; - core->anal->pseudo = node->i_value; return true; } See the r_anal.h comment static bool cb_asmpseudo(void *user, void *data) { RCore *core = (RCore *) user; RConfigNode *node = (RConfigNode *) data; core->rasm->pseudo = node->i_value; return true; }
codereview_new_cpp_data_8014
R_API void r_core_seek_previous(RCore *core, const char *type) { r_flag_foreach (core->flags, seek_flag_offset, &u); found = u.found; } - if (found == true) { r_core_seek (core, next, true); } } ```suggestion if (found) { ``` R_API void r_core_seek_previous(RCore *core, const char *type) { r_flag_foreach (core->flags, seek_flag_offset, &u); found = u.found; } + if (found) { r_core_seek (core, next, true); } }
codereview_new_cpp_data_8015
static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data ripend = "]"; } char * maybe_num = neg? neg+1 : rip; - if( r_is_valid_input_num_value(NULL, maybe_num)){ if (neg) { - repl_num -= r_num_get(NULL, maybe_num); } else { - repl_num += r_num_get(NULL, maybe_num); } rip -= 3; *rip = 0; ```suggestion if (r_is_valid_input_num_value (NULL, maybe_num)) { ``` static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data ripend = "]"; } char * maybe_num = neg? neg+1 : rip; + if (r_is_valid_input_num_value (NULL, maybe_num)) { if (neg) { + repl_num -= r_num_get (NULL, maybe_num); } else { + repl_num += r_num_get (NULL, maybe_num); } rip -= 3; *rip = 0;
codereview_new_cpp_data_8016
jmp $$ + 4 + ( [delta] * 2 ) op->stackop = R_ANAL_STACK_GET; op->stackptr = 0; op->ptr = -MEMDISP (1); - } else if (REGBASE(1) == ARM_REG_PC && !HASMEMINDEX(1)) { op->ptr = (addr & ~3LL) + (thumb? 4: 8) + MEMDISP (1); op->refptr = 4; if (REGID(0) == ARM_REG_PC && insn->detail->arm.cc != ARM_CC_AL) { ```suggestion } else if (REGBASE (1) == ARM_REG_PC && !HASMEMINDEX (1)) { ``` jmp $$ + 4 + ( [delta] * 2 ) op->stackop = R_ANAL_STACK_GET; op->stackptr = 0; op->ptr = -MEMDISP (1); + } else if (REGBASE (1) == ARM_REG_PC && !HASMEMINDEX (1)) { op->ptr = (addr & ~3LL) + (thumb? 4: 8) + MEMDISP (1); op->refptr = 4; if (REGID(0) == ARM_REG_PC && insn->detail->arm.cc != ARM_CC_AL) {
codereview_new_cpp_data_8017
static int make_projects_directory(RCore *core) { R_API bool r_core_is_project(RCore *core, const char *name) { bool ret = false; - if (!R_STR_ISEMPTY (name) && *name != '.') { char *path = get_project_script_path (core, name); if (!path) { return false; ```suggestion if (R_STR_ISNOTEMPTY (name) && *name != '.') { ``` static int make_projects_directory(RCore *core) { R_API bool r_core_is_project(RCore *core, const char *name) { bool ret = false; + if (R_STR_ISNOTEMPTY (name) && *name != '.') { char *path = get_project_script_path (core, name); if (!path) { return false;
codereview_new_cpp_data_8018
static const char *help_msg_c[] = { "c", " [string]", "compare a plain with escaped chars string", "c*", " [string]", "same as above, but printing r2 commands instead", "c1", " [addr]", "compare byte at addr with current offset", - "c2", "* [value]", "compare word at offset with given value", - "c4", "* [value]", "compare doubleword at offset with given value", - "c8", "* [value]", "compare quadword at offset with given value", "cat", " [file]", "show contents of file (see pwd, ls)", "cc", " [at]", "compares in two hexdump columns of block size", "ccc", " [at]", "same as above, but only showing different lines", the * is optional ```suggestion "c2", "[*] [value]", "compare word at offset with given value", ``` static const char *help_msg_c[] = { "c", " [string]", "compare a plain with escaped chars string", "c*", " [string]", "same as above, but printing r2 commands instead", "c1", " [addr]", "compare byte at addr with current offset", + "c2", "[*] [value]", "compare word at offset with given value", + "c4", "[*] [value]", "compare doubleword at offset with given value", + "c8", "[*] [value]", "compare quadword at offset with given value", "cat", " [file]", "show contents of file (see pwd, ls)", "cc", " [at]", "compares in two hexdump columns of block size", "ccc", " [at]", "same as above, but only showing different lines",
codereview_new_cpp_data_8019
static inline RBinWasmSection *sections_first_custom_name(RBinWasmObj *bin) { RBinWasmSection *sec; r_list_foreach (bin->g_sections, iter, sec) { if (sec->id == R_BIN_WASM_SECTION_CUSTOM && sec->size > 6) { - ut8 _tmp[CUST_NAME_START_LEN]; r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN); if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { return sec; ```suggestion ut8 _tmp[CUST_NAME_START_LEN] = {0}; ``` static inline RBinWasmSection *sections_first_custom_name(RBinWasmObj *bin) { RBinWasmSection *sec; r_list_foreach (bin->g_sections, iter, sec) { if (sec->id == R_BIN_WASM_SECTION_CUSTOM && sec->size > 6) { + ut8 _tmp[CUST_NAME_START_LEN] = {0}; r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN); if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { return sec;
codereview_new_cpp_data_8020
static inline RBinWasmSection *sections_first_custom_name(RBinWasmObj *bin) { r_list_foreach (bin->g_sections, iter, sec) { if (sec->id == R_BIN_WASM_SECTION_CUSTOM && sec->size > 6) { ut8 _tmp[CUST_NAME_START_LEN] = {0}; - r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN); - if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { - return sec; } } } ```suggestion if (r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN) > 0) { ``` static inline RBinWasmSection *sections_first_custom_name(RBinWasmObj *bin) { r_list_foreach (bin->g_sections, iter, sec) { if (sec->id == R_BIN_WASM_SECTION_CUSTOM && sec->size > 6) { ut8 _tmp[CUST_NAME_START_LEN] = {0}; + if (r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN) > 0) { + if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { + return sec; + } } } }
codereview_new_cpp_data_8021
static inline RBinWasmSection *sections_first_custom_name(RBinWasmObj *bin) { r_list_foreach (bin->g_sections, iter, sec) { if (sec->id == R_BIN_WASM_SECTION_CUSTOM && sec->size > 6) { ut8 _tmp[CUST_NAME_START_LEN] = {0}; - r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN); - if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { - return sec; } } } ```suggestion if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { ``` static inline RBinWasmSection *sections_first_custom_name(RBinWasmObj *bin) { r_list_foreach (bin->g_sections, iter, sec) { if (sec->id == R_BIN_WASM_SECTION_CUSTOM && sec->size > 6) { ut8 _tmp[CUST_NAME_START_LEN] = {0}; + if (r_buf_read_at (buf, sec->offset, _tmp, CUST_NAME_START_LEN) > 0) { + if (!memcmp (CUST_NAME_START, _tmp, CUST_NAME_START_LEN)) { + return sec; + } } } }
codereview_new_cpp_data_8022
static void visual_refresh(RCore *core); -#define PROMPTSTR "> "; // remove globals pls static R_TH_LOCAL int obs = 0; static R_TH_LOCAL int blocksize = 0; ```suggestion #define PROMPTSTR "> " ``` static void visual_refresh(RCore *core); +#define PROMPTSTR "> " // remove globals pls static R_TH_LOCAL int obs = 0; static R_TH_LOCAL int blocksize = 0;
codereview_new_cpp_data_8023
void (rm_op)(struct op_parameter par) { op_obj->op_name = r_str_newf ("<%u>", par.op_code); op_obj->type = op_obj->op_pop = op_obj->op_push = 0; } else { - R_LOG_ERROR ("Error in rm_op() while constructing opcodes for .pyc file: .op_code = %u, .op_name = %s", par.op_code, par.op_name); } } ```suggestion R_LOG_ERROR ("Error in rm_op() while constructing opcodes for .pyc file: \n .op_code = %u, .op_name = %s", par.op_code, par.op_name); ``` void (rm_op)(struct op_parameter par) { op_obj->op_name = r_str_newf ("<%u>", par.op_code); op_obj->type = op_obj->op_pop = op_obj->op_push = 0; } else { + R_LOG_ERROR ("Error in rm_op() while constructing opcodes for .pyc file: \n .op_code = %u, .op_name = %s", par.op_code, par.op_name); } }
codereview_new_cpp_data_8024
void (rm_op)(struct op_parameter par) { op_obj->op_name = r_str_newf ("<%u>", par.op_code); op_obj->type = op_obj->op_pop = op_obj->op_push = 0; } else { - R_LOG_ERROR ("Error in rm_op() while constructing opcodes for .pyc file: .op_code = %u, .op_name = %s", par.op_code, par.op_name); } } ```suggestion R_LOG_ERROR ("Error in rm_op() while constructing opcodes for .pyc file: \n .op_code = %u, .op_name = %s", par.op_code, par.op_name); ``` void (rm_op)(struct op_parameter par) { op_obj->op_name = r_str_newf ("<%u>", par.op_code); op_obj->type = op_obj->op_pop = op_obj->op_push = 0; } else { + R_LOG_ERROR ("Error in rm_op() while constructing opcodes for .pyc file: \n .op_code = %u, .op_name = %s", par.op_code, par.op_name); } }
codereview_new_cpp_data_8025
static RBinWasmCustomNameEntry *parse_custom_name_entry(RBinWasmObj *bin, ut64 b } break; default: - R_LOG_WARN ("[wasm] Halting custom name section parsing at unknown type 0x%x offset 0x%" PFMTSZx "", cust->type, start); cust->type = R_BIN_WASM_NAMETYPE_None; goto beach; } ```suggestion R_LOG_WARN ("[wasm] Halting custom name section parsing at unknown type 0x%x offset 0x%" PFMTSZx, cust->type, start); ``` static RBinWasmCustomNameEntry *parse_custom_name_entry(RBinWasmObj *bin, ut64 b } break; default: + R_LOG_WARN ("[wasm] Halting custom name section parsing at unknown type 0x%x offset 0x%" PFMTSZx, cust->type, start); cust->type = R_BIN_WASM_NAMETYPE_None; goto beach; }
codereview_new_cpp_data_8026
static bool objc_find_refs(RCore *core) { } if (classMethodsVA > to) { - R_LOG_WARN ("Warning: Fuzzed binary or bug in here, checking next %"PFMT64x" !< %"PFMT64x"", classMethodsVA, to); break; } for (va = classMethodsVA; va < to; va += objc2ClassMethSize) { ```suggestion R_LOG_WARN ("Warning: Fuzzed binary or bug in here, checking next %"PFMT64x" !< %"PFMT64x, classMethodsVA, to); ``` static bool objc_find_refs(RCore *core) { } if (classMethodsVA > to) { + R_LOG_WARN ("Warning: Fuzzed binary or bug in here, checking next %"PFMT64x" !< %"PFMT64x, classMethodsVA, to); break; } for (va = classMethodsVA; va < to; va += objc2ClassMethSize) {
codereview_new_cpp_data_8027
static bool __is_data_block_cb(RAnalBlock *block, void *user) { static int __isdata(RCore *core, ut64 addr) { if (!r_io_is_valid_offset (core->io, addr, false)) { - // R_LOG_WARN ("Warning: Invalid memory address at 0x%08"PFMT64x"", addr); return 4; } ```suggestion // R_LOG_WARN ("Warning: Invalid memory address at 0x%08"PFMT64x, addr); ``` static bool __is_data_block_cb(RAnalBlock *block, void *user) { static int __isdata(RCore *core, ut64 addr) { if (!r_io_is_valid_offset (core->io, addr, false)) { + // R_LOG_WARN ("Warning: Invalid memory address at 0x%08"PFMT64x, addr); return 4; }
codereview_new_cpp_data_8028
R_API void r_core_visual_define(RCore *core, const char *args, int distance) { int rc = r_anal_op (core->anal, &op, off, core->block + off - core->offset, 32, R_ANAL_OP_MASK_BASIC); if (rc < 1) { - R_LOG_ERROR ("Error analyzing opcode at 0x%08"PFMT64x"", off); } else { tgt_addr = op.jump != UT64_MAX ? op.jump : op.ptr; RAnalVar *var = r_anal_get_used_function_var (core->anal, op.addr); ```suggestion R_LOG_ERROR ("Error analyzing opcode at 0x%08"PFMT64x, off); ``` R_API void r_core_visual_define(RCore *core, const char *args, int distance) { int rc = r_anal_op (core->anal, &op, off, core->block + off - core->offset, 32, R_ANAL_OP_MASK_BASIC); if (rc < 1) { + R_LOG_ERROR ("Error analyzing opcode at 0x%08"PFMT64x, off); } else { tgt_addr = op.jump != UT64_MAX ? op.jump : op.ptr; RAnalVar *var = r_anal_get_used_function_var (core->anal, op.addr);
codereview_new_cpp_data_8029
R_API void r_w32_identify_window(void) { return; } if (!win) { - R_LOG_ERROR ("Error trying to get information from 0x%08"PFMT64x"", (ut64)hwnd); return; } RTable *tbl = __create_window_table (); ```suggestion R_LOG_ERROR ("Error trying to get information from 0x%08"PFMT64x, (ut64)hwnd); ``` R_API void r_w32_identify_window(void) { return; } if (!win) { + R_LOG_ERROR ("Error trying to get information from 0x%08"PFMT64x, (ut64)hwnd); return; } RTable *tbl = __create_window_table ();
codereview_new_cpp_data_8030
R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to) { if (r_io_write_at (io, r_itv_begin (c->itv), c->data, r_itv_size (c->itv))) { c->written = true; } else { - R_LOG_ERROR ("Error writing change at 0x%08"PFMT64x"", r_itv_begin (c->itv)); } io->cached = cached; // break; // XXX old behavior, revisit this ```suggestion R_LOG_ERROR ("Error writing change at 0x%08"PFMT64x, r_itv_begin (c->itv)); ``` R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to) { if (r_io_write_at (io, r_itv_begin (c->itv), c->data, r_itv_size (c->itv))) { c->written = true; } else { + R_LOG_ERROR ("Error writing change at 0x%08"PFMT64x, r_itv_begin (c->itv)); } io->cached = cached; // break; // XXX old behavior, revisit this
codereview_new_cpp_data_8031
static bool __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int de const char *cc = r_anal_cc_default (core->anal); if (!cc) { if (r_anal_cc_once (core->anal)) { - R_LOG_WARN ("set your favourite calling convention in `e anal.cc=?`"); } cc = "reg"; } revert this line as it seems to break some tests. we will look later at them ```suggestion eprintf ("Warning: set your favourite calling convention in `e anal.cc=?`\n"); ``` static bool __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int de const char *cc = r_anal_cc_default (core->anal); if (!cc) { if (r_anal_cc_once (core->anal)) { + eprintf ("Warning: set your favourite calling convention in `e anal.cc=?`\n"); } cc = "reg"; }
codereview_new_cpp_data_8032
R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { } if (stage == STAGES - 1) { if (ret < 1) { - R_LOG_ERROR ("Cannot assemble '%s' at line %d", ptr_start, linenum); goto fail; } acode->len = idx + ret; ```suggestion eprintf ("Cannot assemble '%s' at line %d\n", ptr_start, linenum); ``` R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { } if (stage == STAGES - 1) { if (ret < 1) { + eprintf ("Cannot assemble '%s' at line %d\n", ptr_start, linenum); goto fail; } acode->len = idx + ret;
codereview_new_cpp_data_8033
R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { RIODesc *fd = fs->iob.open_at (fs->iob.io, uri, R_PERM_RW, 0, 0); free (uri); if (fd) { - r_io_desc_write (fd, file->data, file->size); r_list_free (list); return true; } you cant use the r_io_api use fs->iob.fd_write R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { RIODesc *fd = fs->iob.open_at (fs->iob.io, uri, R_PERM_RW, 0, 0); free (uri); if (fd) { + fs->iob.fd_write (fs->iob.io, fd->fd, file->data, file->size); r_list_free (list); return true; }
codereview_new_cpp_data_8034
static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { char out[32]; - unsigned char code[3] = {0}; memcpy (code, data, R_MIN (sizeof(code), len)); int ilen = i8080_disasm (code, out, len); if (mask & R_ANAL_OP_MASK_DISASM) { ```suggestion ut8 code[3] = {0}; ``` static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { char out[32]; + ut8 code[3] = {0}; memcpy (code, data, R_MIN (sizeof(code), len)); int ilen = i8080_disasm (code, out, len); if (mask & R_ANAL_OP_MASK_DISASM) {
codereview_new_cpp_data_8035
static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { char out[32]; - unsigned char code[3] = {0}; memcpy (code, data, R_MIN (sizeof(code), len)); int ilen = i8080_disasm (code, out, len); if (mask & R_ANAL_OP_MASK_DISASM) { ```suggestion memcpy (code, data, R_MIN (sizeof (code), len)); ``` static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { char out[32]; + ut8 code[3] = {0}; memcpy (code, data, R_MIN (sizeof(code), len)); int ilen = i8080_disasm (code, out, len); if (mask & R_ANAL_OP_MASK_DISASM) {
codereview_new_cpp_data_8036
static int archinfo(RAnal *anal, int q) { case R_ANAL_ARCHINFO_MIN_OP_SIZE: return 2; case R_ANAL_ARCHINFO_DATA_ALIGN: const char *cpu = anal->config->cpu; if (strstr (cpu, "68030") || strstr (cpu, "68040") || strstr (cpu, "68060")) { return 1; - } else { - return 2; } } return 2; Dont else after return static int archinfo(RAnal *anal, int q) { case R_ANAL_ARCHINFO_MIN_OP_SIZE: return 2; case R_ANAL_ARCHINFO_DATA_ALIGN: + { const char *cpu = anal->config->cpu; if (strstr (cpu, "68030") || strstr (cpu, "68040") || strstr (cpu, "68060")) { return 1; + } + return 2; } } return 2;
codereview_new_cpp_data_8037
char* Elf_(r_bin_elf_get_arch)(ELFOBJ *bin) { case EM_X86_64: return strdup("x86"); case EM_NONE: - return strdup("No machine"); default: return strdup ("Unknown or unsupported arch"); } } ```suggestion return strdup ("null"); ``` what do you think about this? this way it will use the "null" plugin to disassemble, analyze, .. char* Elf_(r_bin_elf_get_arch)(ELFOBJ *bin) { case EM_X86_64: return strdup("x86"); case EM_NONE: + return strdup ("null"); default: return strdup ("Unknown or unsupported arch"); } }
codereview_new_cpp_data_8038
char* Elf_(r_bin_elf_get_arch)(ELFOBJ *bin) { case EM_X86_64: return strdup("x86"); case EM_NONE: - return strdup("No machine"); default: return strdup ("Unknown or unsupported arch"); } } ```suggestion return strdup ("x86"); ``` char* Elf_(r_bin_elf_get_arch)(ELFOBJ *bin) { case EM_X86_64: return strdup("x86"); case EM_NONE: + return strdup ("null"); default: return strdup ("Unknown or unsupported arch"); } }
codereview_new_cpp_data_8039
static ut32 ccmn(ArmOp *op, const char *str) { } else { return data; } - ut32 data = k | (op->operands[0].reg & 0x7) << 29; data |= (op->operands[0].reg & 0x18) << 13; data |= (op->operands[1].reg & 0x1f) << 8; data |= (op->operands[2].immediate & 0xf) << 24; ```suggestion data = k | (op->operands[0].reg & 0x7) << 29; ``` static ut32 ccmn(ArmOp *op, const char *str) { } else { return data; } + data = k | (op->operands[0].reg & 0x7) << 29; data |= (op->operands[0].reg & 0x18) << 13; data |= (op->operands[1].reg & 0x1f) << 8; data |= (op->operands[2].immediate & 0xf) << 24;
codereview_new_cpp_data_8040
static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; - if (input[3] != ' ') { - bool fullGraph = false; r_list_foreach (obj->classes, iter, cls) { - if (cls->super && strstr (cls->super, input + 3)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); - } else if (strstr (cls->name, input + 3)){ r_cons_printf ("agn %s\n", cls->name); } } i think you mean == ' ' static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; + if (input[2] == 's') { + const char *match = input + 4; r_list_foreach (obj->classes, iter, cls) { + if (cls->super && strstr (cls->super, match)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); + } else if (strstr (cls->name, match)) { r_cons_printf ("agn %s\n", cls->name); } }
codereview_new_cpp_data_8041
static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; - if (input[3] != ' ') { - bool fullGraph = false; r_list_foreach (obj->classes, iter, cls) { - if (cls->super && strstr (cls->super, input + 3)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); - } else if (strstr (cls->name, input + 3)){ r_cons_printf ("agn %s\n", cls->name); } } ```suggestion } else if (strstr (cls->name, input + 3)) { ``` static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; + if (input[2] == 's') { + const char *match = input + 4; r_list_foreach (obj->classes, iter, cls) { + if (cls->super && strstr (cls->super, match)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); + } else if (strstr (cls->name, match)) { r_cons_printf ("agn %s\n", cls->name); } }
codereview_new_cpp_data_8042
static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; - if (input[3] != ' ') { - bool fullGraph = false; r_list_foreach (obj->classes, iter, cls) { - if (cls->super && strstr (cls->super, input + 3)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); - } else if (strstr (cls->name, input + 3)){ r_cons_printf ("agn %s\n", cls->name); } } keep that input+3 pointer in a variable outside the loop static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; + if (input[2] == 's') { + const char *match = input + 4; r_list_foreach (obj->classes, iter, cls) { + if (cls->super && strstr (cls->super, match)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); + } else if (strstr (cls->name, match)) { r_cons_printf ("agn %s\n", cls->name); } }
codereview_new_cpp_data_8043
static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; - if (input[2] == ' ' && strcmp(input + 3, "")) { const char *match = r_str_trim_head_ro (input + 3); r_list_foreach (obj->classes, iter, cls) { if (cls->super && strstr (cls->super, match)) { what's exactly what you wanna check here? if there's a space and not a null byte after it? ```suggestion if (input[2] == ' ' && input[3]) { ``` then this code is simpler and more readable, but what if there are many spaces? you shoul dbetter do something like this: ```suggestion const char *match = r_str_trim_head_ro (input + 2); if (*match) { ``` static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; + const char *match = r_str_trim_head_ro (input + 2); + if (*match) { const char *match = r_str_trim_head_ro (input + 3); r_list_foreach (obj->classes, iter, cls) { if (cls->super && strstr (cls->super, match)) {
codereview_new_cpp_data_8044
static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; - if (input[2] == ' ' && strcmp(input + 3, "")) { const char *match = r_str_trim_head_ro (input + 3); r_list_foreach (obj->classes, iter, cls) { if (cls->super && strstr (cls->super, match)) { this can introduce code injection vulnerabilities. quote the whole command and filter the cls->super value. maybe we can have a filtering api to do that automatically static int cmd_info(void *data, const char *input) { break; } bool fullGraph = true; + const char *match = r_str_trim_head_ro (input + 2); + if (*match) { const char *match = r_str_trim_head_ro (input + 3); r_list_foreach (obj->classes, iter, cls) { if (cls->super && strstr (cls->super, match)) {
codereview_new_cpp_data_8045
static int cmd_info(void *data, const char *input) { const char *match = r_str_trim_head_ro (input + 2); if (*match) { r_list_foreach (obj->classes, iter, cls) { - if (cls->super && strstr (cls->super, match)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); } else if (strstr (cls->name, match)) { r_cons_printf ("agn %s\n", cls->name); } } - goto done; } - if (fullGraph) { r_list_foreach (obj->classes, iter, cls) { if (cls->super) { r_cons_printf ("agn %s\n", cls->super); the code below should be after `} else ` otherwise the `grepping` will just print twice and dont work as expected static int cmd_info(void *data, const char *input) { const char *match = r_str_trim_head_ro (input + 2); if (*match) { r_list_foreach (obj->classes, iter, cls) { + if (cls->super && strstr (cls->super, match)) { r_cons_printf ("agn %s\n", cls->super); r_cons_printf ("agn %s\n", cls->name); r_cons_printf ("age %s %s\n", cls->super, cls->name); } else if (strstr (cls->name, match)) { r_cons_printf ("agn %s\n", cls->name); } } } + else if (fullGraph) { r_list_foreach (obj->classes, iter, cls) { if (cls->super) { r_cons_printf ("agn %s\n", cls->super);
codereview_new_cpp_data_8705
int CPyStatics_Initialize(PyObject **statics, for (int i = 0; i < num_items; i++) { PyObject *item = statics[*frozensets++]; Py_INCREF(item); - PySet_Add(obj, item); } *result++ = obj; } Check the return value of `PySet_Add`. int CPyStatics_Initialize(PyObject **statics, for (int i = 0; i < num_items; i++) { PyObject *item = statics[*frozensets++]; Py_INCREF(item); + if (PySet_Add(obj, item) == -1) { + return -1; + } } *result++ = obj; }
codereview_new_cpp_data_9300
_PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value) Py_DECREF(exc_value); } } - if (value != NULL && PyExceptionInstance_Check(value)) tb = PyException_GetTraceback(value); _PyErr_Restore(tstate, Py_NewRef(Py_TYPE(value)), value, tb); } This would crash if `value` is NULL. The if check immediately above suggests that that is possible here. _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value) Py_DECREF(exc_value); } } + assert(value != NULL); + if (PyExceptionInstance_Check(value)) tb = PyException_GetTraceback(value); _PyErr_Restore(tstate, Py_NewRef(Py_TYPE(value)), value, tb); }
codereview_new_cpp_data_9302
notify_func_watchers(PyInterpreterState *interp, PyFunction_WatchEvent event, Py_DECREF(repr); } if (context == NULL) { - context = Py_None; - Py_INCREF(context); } PyErr_WriteUnraisable(context); Py_DECREF(context); ```suggestion context = Py_NewRef(Py_None); ``` notify_func_watchers(PyInterpreterState *interp, PyFunction_WatchEvent event, Py_DECREF(repr); } if (context == NULL) { + context = Py_NewRef(Py_None); } PyErr_WriteUnraisable(context); Py_DECREF(context);
codereview_new_cpp_data_9303
notify_code_watchers(PyCodeEvent event, PyCodeObject *co) Py_DECREF(repr); } if (context == NULL) { - context = Py_None; - Py_INCREF(context); } PyErr_WriteUnraisable(context); Py_DECREF(context); ```suggestion context = Py_NewRef(Py_None); ``` notify_code_watchers(PyCodeEvent event, PyCodeObject *co) Py_DECREF(repr); } if (context == NULL) { + context = Py_NewRef(Py_None); } PyErr_WriteUnraisable(context); Py_DECREF(context);
codereview_new_cpp_data_9304
code_event_name(PyCodeEvent event) { #define CASE(op) \ case PY_CODE_EVENT_##op: \ return "PY_CODE_EVENT_" #op; - FOREACH_CODE_EVENT(CASE) #undef CASE } } static void Need a default and/or error return after the switch. code_event_name(PyCodeEvent event) { #define CASE(op) \ case PY_CODE_EVENT_##op: \ return "PY_CODE_EVENT_" #op; + PY_FOREACH_CODE_EVENT(CASE) #undef CASE } + Py_UNREACHABLE(); } static void
codereview_new_cpp_data_9308
ensure_array_large_enough(int index, void **arr_, int *alloc, int default_alloc, return ERROR; } - if (newsize == 0) { - PyErr_NoMemory(); - return ERROR; - } void *tmp = PyObject_Realloc(arr, newsize); if (tmp == NULL) { PyErr_NoMemory(); Is this possible? ensure_array_large_enough(int index, void **arr_, int *alloc, int default_alloc, return ERROR; } + assert(newsize > 0); void *tmp = PyObject_Realloc(arr, newsize); if (tmp == NULL) { PyErr_NoMemory();
codereview_new_cpp_data_9309
# endif #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define dup _dup -# define dup2 _dup2 -#endif - #if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__DragonFly__) # define FD_DIR "/dev/fd" #else The `_posixsubprocess` extension module shouldn't get built on Windows. # endif #endif #if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__DragonFly__) # define FD_DIR "/dev/fd" #else
codereview_new_cpp_data_9310
getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) path = PyUnicode_AsWideCharString(pathobj, &cchPath); if (path) { #ifdef MS_WINDOWS - const wchar_t *ext; -#ifdef MS_WINDOWS_GAMES - ext = (cchPath >= 4) ? path + cchPath - 4 : NULL; -#endif DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && -#ifdef MS_WINDOWS_GAMES - (ext != NULL) && -#else - SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && -#endif - (CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL) ? Py_True : Py_False; #else struct stat st; @zooba, `PathCchFindExtension()` isn't needed here. The simpler approach that's implemented for `MS_WINDOWS_GAMES` is sufficient. getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) path = PyUnicode_AsWideCharString(pathobj, &cchPath); if (path) { #ifdef MS_WINDOWS DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && + (cchPath >= 4) && + (CompareStringOrdinal(path + cchPath - 4, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL) ? Py_True : Py_False; #else struct stat st;
codereview_new_cpp_data_9311
win32_getppid() } PSS_PROCESS_INFORMATION info; - error = PssQuerySnapshot( - snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info) - ); if (error != ERROR_SUCCESS) { result = PyLong_FromUnsignedLong(info.ParentProcessId); - } else { result = PyErr_SetFromWindowsErr(error); } ```suggestion error = PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info)); if (error != ERROR_SUCCESS) { result = PyLong_FromUnsignedLong(info.ParentProcessId); } else { ``` PEP 7 win32_getppid() } PSS_PROCESS_INFORMATION info; + error = PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, + sizeof(info)); if (error != ERROR_SUCCESS) { result = PyLong_FromUnsignedLong(info.ParentProcessId); + } + else { result = PyErr_SetFromWindowsErr(error); }
codereview_new_cpp_data_9312
extern void bzero(void *, int); # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef MS_WINDOWS_GAMES -# include <winsock2.h> -# else -# include <winsock.h> -# endif #else # define SOCKET int #endif Can we not just use `winsock2.h` unconditionally? extern void bzero(void *, int); # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif +# include <winsock2.h> #else # define SOCKET int #endif
codereview_new_cpp_data_9313
remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else - BOOL isSupported = info.dwMajorVersion >= 10 && - info.dwMinorVersion >= 0 && - info.dwBuildNumber >= win_runtime_flags[i].build_number; #endif if (isSupported) { break; This kind of code is exactly why the `VerifyVersionInfo` function was added ;) ```suggestion BOOL isSupported = info.dwMajorVersion > 10 || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) || (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= win_runtime_flags[i].build_number); ``` remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else + BOOL isSupported = info.dwMajorVersion > 10 || + (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) || + (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && + info.dwBuildNumber >= win_runtime_flags[i].build_number); #endif if (isSupported) { break;
codereview_new_cpp_data_9314
_Py_stat(PyObject *path, struct stat *statbuf) } #ifdef MS_WINDOWS #ifndef HANDLE_FLAG_INHERIT #define HANDLE_FLAG_INHERIT 0x00000001 #endif ```suggestion #ifdef MS_WINDOWS // For some Windows API partitions, SetHandleInformation() is declared // but none of the handle flags are defined. ``` _Py_stat(PyObject *path, struct stat *statbuf) } #ifdef MS_WINDOWS +// For some Windows API partitions, SetHandleInformation() is declared +// but none of the handle flags are defined. #ifndef HANDLE_FLAG_INHERIT #define HANDLE_FLAG_INHERIT 0x00000001 #endif
codereview_new_cpp_data_9315
remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else BOOL isSupported = info.dwMajorVersion > 10 || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) || (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && ```suggestion /* note in this case 'info' is the actual OS version, whereas above it is the version to compare against. */ BOOL isSupported = info.dwMajorVersion > 10 || ``` remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else + /* note in this case 'info' is the actual OS version, whereas above + it is the version to compare against. */ BOOL isSupported = info.dwMajorVersion > 10 || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) || (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 &&
codereview_new_cpp_data_9316
#include "structmember.h" // PyMemberDef #include <stddef.h> // offsetof() -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) #ifndef MS_WINDOWS #define UNIX We can't support the system API partition until `mmap` is updated to call `CreateFileMappingW()` and `OpenFileMappingW()`. As of 10.0.19041, "winbase.h" declares the ANSI versions only for desktop and games. ```suggestion #if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) ``` #include "structmember.h" // PyMemberDef #include <stddef.h> // offsetof() +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) #ifndef MS_WINDOWS #define UNIX
codereview_new_cpp_data_9317
sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, Py_BEGIN_ALLOW_THREADS fd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, - FROM_PROTOCOL_INFO, &info, 0, - WSA_FLAG_OVERLAPPED ); Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error(); ```suggestion WSA_FLAG_OVERLAPPED); ``` sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, Py_BEGIN_ALLOW_THREADS fd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, + FROM_PROTOCOL_INFO, &info, 0, WSA_FLAG_OVERLAPPED); Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error();
codereview_new_cpp_data_9318
random_seed_time_pid(RandomObject *self) key[0] = (uint32_t)(now & 0xffffffffU); key[1] = (uint32_t)(now >> 32); -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) key[2] = (uint32_t)GetCurrentProcessId(); #elif defined(HAVE_GETPID) key[2] = (uint32_t)getpid(); The CRT defines `_CRT_USE_WINAPI_FAMILY_DESKTOP_APP` for the `DESKTOP` and `SYSTEM` API partitions in "corecrt.h". This macro determines whether or not `_getpid()` is defined. ```suggestion #if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) && !defined(MS_WINDOWS_SYSTEM) ``` random_seed_time_pid(RandomObject *self) key[0] = (uint32_t)(now & 0xffffffffU); key[1] = (uint32_t)(now >> 32); +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) && !defined(MS_WINDOWS_SYSTEM) key[2] = (uint32_t)GetCurrentProcessId(); #elif defined(HAVE_GETPID) key[2] = (uint32_t)getpid();
codereview_new_cpp_data_9319
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) Py_RETURN_NONE; } } -#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */ ```suggestion #endif /* HAVE_WINDOWS_CONSOLE_IO */ ``` os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) Py_RETURN_NONE; } } +#endif /* HAVE_WINDOWS_CONSOLE_IO */ /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */
codereview_new_cpp_data_9320
sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) newfd = ctx.result; #ifdef MS_WINDOWS -#ifdef MS_WINDOWS_DESKTOP if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { PyErr_SetFromWindowsErr(0); SOCKETCLOSE(newfd); In 10.0.19041, `SetHandleInformation()` is available for `APP`, `SYSTEM`, and `GAMES`. Your experiment with modifying `HANDLE_FLAG_INHERIT` on Xbox failed with `ERROR_ACCESS_DENIED`, right? In that case, I suggest supporting everything but `GAMES`. ```suggestion #if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) #ifndef HANDLE_FLAG_INHERIT #define HANDLE_FLAG_INHERIT 0x00000001 #endif ``` sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) newfd = ctx.result; #ifdef MS_WINDOWS +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) +#ifndef HANDLE_FLAG_INHERIT +#define HANDLE_FLAG_INHERIT 0x00000001 +#endif if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { PyErr_SetFromWindowsErr(0); SOCKETCLOSE(newfd);
codereview_new_cpp_data_9321
_Py_abspath(const wchar_t *path, wchar_t **abspath_p) // Note that this implementation does not handle all the same cases as the real // function, but we expect games are very unlikely to encounter the more obscure // cases. -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) HRESULT PathCchSkipRoot(const wchar_t *path, const wchar_t **rootEnd) { ```suggestion #if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) ``` _Py_abspath(const wchar_t *path, wchar_t **abspath_p) // Note that this implementation does not handle all the same cases as the real // function, but we expect games are very unlikely to encounter the more obscure // cases. +#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) HRESULT PathCchSkipRoot(const wchar_t *path, const wchar_t **rootEnd) {
codereview_new_cpp_data_9322
PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, } return S_OK; } -#endif /* MS_WINDOWS && !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ // The caller must ensure "buffer" is big enough. static int ```suggestion #endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */ ``` PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, } return S_OK; } +#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */ // The caller must ensure "buffer" is big enough. static int
codereview_new_cpp_data_9323
PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, size_t file_len = relfile ? wcslen(relfile) : 0; /* path is at max dirname + filename + backslash + \0 */ size_t new_len = dir_len + file_len + 2; - if (bufsize >= MAXPATHLEN || new_len > bufsize) { return E_INVALIDARG; } The value of `bufsize` isn't limited. The result length may be limited. If `PATHCCH_ALLOW_LONG_PATHS` isn't set in `flags`, and `new_len >= MAX_PATH` (not `MAXPATHLEN`), the returned error should be `HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE)`. Else if `new_len` is greater than `bufsize`, the returned error should be `HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)`. `PATHCCH_ALLOW_LONG_PATHS` also determines whether to convert to or from an extended path, depending on whether the current process supports long paths (Python 3.6+ does). But it's okay to omit that behavior for `GAMES`. PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, size_t file_len = relfile ? wcslen(relfile) : 0; /* path is at max dirname + filename + backslash + \0 */ size_t new_len = dir_len + file_len + 2; + if (new_len > bufsize) { return E_INVALIDARG; }
codereview_new_cpp_data_9324
_PyGen_FetchStopIterationValue(PyObject **pvalue) PyObject *value = NULL; if (PyErr_ExceptionMatches(PyExc_StopIteration)) { PyObject *exc = PyErr_GetRaisedException(); - if (exc) { - /* exception will usually be normalised already */ - value = Py_NewRef(((PyStopIterationObject *)exc)->value); - Py_DECREF(exc); - } } else if (PyErr_Occurred()) { return -1; } If `PyErr_ExceptionMatches` return true, doesn't that mean that `PyErr_GetRaisedException()` must return non-NULL? _PyGen_FetchStopIterationValue(PyObject **pvalue) PyObject *value = NULL; if (PyErr_ExceptionMatches(PyExc_StopIteration)) { PyObject *exc = PyErr_GetRaisedException(); + value = Py_NewRef(((PyStopIterationObject *)exc)->value); + Py_DECREF(exc); } else if (PyErr_Occurred()) { return -1; }