Skip to content

Commit

Permalink
decrease C_style cast
Browse files Browse the repository at this point in the history
  • Loading branch information
nishinji committed Sep 6, 2024
1 parent 3f62275 commit 6553ce2
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion vita3k/Windows.manifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--
Vita3K emulator project
Copyright (C) 2021 Vita3K team
Copyright (C) 2024 Vita3K team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
4 changes: 2 additions & 2 deletions vita3k/config/include/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ enum ScreenshotFormat {
code(bool, "ngs-enable", true, ngs_enable) \
code(int, "sys-button", static_cast<int>(SCE_SYSTEM_PARAM_ENTER_BUTTON_CROSS), sys_button) \
code(int, "sys-lang", static_cast<int>(SCE_SYSTEM_PARAM_LANG_ENGLISH_US), sys_lang) \
code(int, "sys-date-format", (int)SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY, sys_date_format) \
code(int, "sys-time-format", (int)SCE_SYSTEM_PARAM_TIME_FORMAT_12HOUR, sys_time_format) \
code(int, "sys-date-format", static_cast<int>(SCE_SYSTEM_PARAM_DATE_FORMAT_MMDDYYYY), sys_date_format)\
code(int, "sys-time-format", static_cast<int>(SCE_SYSTEM_PARAM_TIME_FORMAT_12HOUR), sys_time_format)\
code(int, "cpu-pool-size", 10, cpu_pool_size) \
code(int, "modules-mode", static_cast<int>(ModulesMode::AUTOMATIC), modules_mode) \
code(int, "delay-background", 4, delay_background) \
Expand Down
18 changes: 9 additions & 9 deletions vita3k/gui/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static void init_font(GuiState &gui, EmuEnvState &emuenv) {
large_font_config.SizePixels = 116.f;
gui.large_font = io.Fonts->AddFontFromFileTTF(fs_utils::path_to_utf8(latin_fw_font_path).c_str(), large_font_config.SizePixels, &large_font_config, large_font_chars);
} else {
LOG_WARN("Could not find firmware font file at \"{}\", install firmware fonts package to fix this.", latin_fw_font_path);
LOG_WARN("Could not find firmware font file at {}, install firmware fonts package to fix this.", latin_fw_font_path);
font_config.SizePixels = 22.f;

// Set up default font path
Expand All @@ -261,7 +261,7 @@ static void init_font(GuiState &gui, EmuEnvState &emuenv) {

LOG_INFO("Using default Vita3K font.");
} else
LOG_WARN("Could not find default Vita3K font at \"{}\", using default ImGui font.", default_font_path);
LOG_WARN("Could not find default Vita3K font at {}, using default ImGui font.", default_font_path);
}

// Build font atlas loaded and upload to GPU
Expand Down Expand Up @@ -423,18 +423,18 @@ static bool get_user_apps(GuiState &gui, EmuEnvState &emuenv) {
gui.app_selector.user_apps.clear();
// Read size of apps list
size_t size;
apps_cache.read((char *)&size, sizeof(size));
apps_cache.read(reinterpret_cast<char *>(&size), sizeof(size));

// Check version of cache
uint32_t versionInFile;
apps_cache.read((char *)&versionInFile, sizeof(uint32_t));
apps_cache.read(reinterpret_cast<char *>(&versionInFile), sizeof(uint32_t));
if (versionInFile != 1) {
LOG_WARN("Current version of cache: {}, is outdated, recreate it.", versionInFile);
return false;
}

// Read language of cache
apps_cache.read((char *)&gui.app_selector.apps_cache_lang, sizeof(uint32_t));
apps_cache.read(reinterpret_cast<char *>(&gui.app_selector.apps_cache_lang), sizeof(uint32_t));
if (gui.app_selector.apps_cache_lang != emuenv.cfg.sys_lang) {
LOG_WARN("Current lang of cache: {}, is different configuration: {}, recreate it.", get_sys_lang_name(gui.app_selector.apps_cache_lang), get_sys_lang_name(emuenv.cfg.sys_lang));
return false;
Expand All @@ -445,7 +445,7 @@ static bool get_user_apps(GuiState &gui, EmuEnvState &emuenv) {
auto read = [&apps_cache]() {
size_t size;

apps_cache.read((char *)&size, sizeof(size));
apps_cache.read(reinterpret_cast<char *>(&size), sizeof(size));

std::vector<char> buffer(size); // dont trust std::string to hold buffer enough
apps_cache.read(buffer.data(), size);
Expand Down Expand Up @@ -488,18 +488,18 @@ void save_apps_cache(GuiState &gui, EmuEnvState &emuenv) {

// Write version of cache
const uint32_t versionInFile = 1;
apps_cache.write((const char *)&versionInFile, sizeof(uint32_t));
apps_cache.write(reinterpret_cast<const char *>(&versionInFile), sizeof(uint32_t));

// Write language of cache
gui.app_selector.apps_cache_lang = emuenv.cfg.sys_lang;
apps_cache.write((char *)&gui.app_selector.apps_cache_lang, sizeof(uint32_t));
apps_cache.write(reinterpret_cast<char *>(&gui.app_selector.apps_cache_lang), sizeof(uint32_t));

// Write Apps list
for (const App &app : gui.app_selector.user_apps) {
auto write = [&apps_cache](const std::string &i) {
const auto size = i.length();

apps_cache.write((const char *)&size, sizeof(size));
apps_cache.write(reinterpret_cast<const char *>(&size), sizeof(size));
apps_cache.write(i.c_str(), size);
};

Expand Down
2 changes: 1 addition & 1 deletion vita3k/gui/src/manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void draw_manual(GuiState &gui, EmuEnvState &emuenv) {
}

// Draw right button
if (current_page < (int)gui.manuals.size() - 1) {
if (current_page < static_cast<int>(gui.manuals.size()) - 1) {
ImGui::SetCursorPos(ImVec2(display_size.x - (70.f * SCALE.x), display_size.y - (40.0f * SCALE.y)));
if ((!hidden_button && ImGui::Button(">", BUTTON_SIZE)) || ImGui::IsKeyPressed(static_cast<ImGuiKey>(emuenv.cfg.keyboard_leftstick_right))) {
scroll = 0.f;
Expand Down
6 changes: 3 additions & 3 deletions vita3k/gui/src/trophy_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ static bool load_trophy_progress(IOState &io, const SceUID &progress_input_file,
}

// Read trophy count by group
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_count_by_group.data(), (uint32_t)np_com_id_info[np_com_id].context.trophy_count_by_group.size() * 4) != (int)np_com_id_info[np_com_id].context.trophy_count_by_group.size() * 4) {
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_count_by_group.data(), (uint32_t)np_com_id_info[np_com_id].context.trophy_count_by_group.size() * 4) != static_cast<int>(np_com_id_info[np_com_id].context.trophy_count_by_group.size()) * 4) {
LOG_ERROR("Fail read trophy count by group");
return false;
}

// Read trophy timestamps
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.unlock_timestamps.data(), (uint32_t)np_com_id_info[np_com_id].context.unlock_timestamps.size() * 8) != (int)np_com_id_info[np_com_id].context.unlock_timestamps.size() * 8) {
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.unlock_timestamps.data(), (uint32_t)np_com_id_info[np_com_id].context.unlock_timestamps.size() * 8) != static_cast<int>(np_com_id_info[np_com_id].context.unlock_timestamps.size()) * 8) {
LOG_ERROR("Fail read unlock_timestamp");
return false;
}

// Read trophy type
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_kinds.data(), (uint32_t)np_com_id_info[np_com_id].context.trophy_kinds.size() * 4) != (int)np_com_id_info[np_com_id].context.trophy_kinds.size() * 4) {
if (read_trophy_progress_file(np_com_id_info[np_com_id].context.trophy_kinds.data(), (uint32_t)np_com_id_info[np_com_id].context.trophy_kinds.size() * 4) != static_cast<int>(np_com_id_info[np_com_id].context.trophy_kinds.size()) * 4) {
LOG_ERROR("Fail read trophy type");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion vita3k/kernel/src/sync_primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,7 +1842,7 @@ SceSize msgpipe_send(KernelState &kernel, const char *export_name, SceUID thread
SceSize insertedSize = (SceSize)msgpipe->data_buffer.Insert(pSendBuf, sendSize);
// msgpipe->senders->erase(wait_data); //Don't erase ourselves - recv will do it
wakeup_receivers();
return (int)insertedSize;
return static_cast<int>(insertedSize);
};

if (!pTimeout) { // No timeout - loop forever until we can fill the buffer
Expand Down
8 changes: 4 additions & 4 deletions vita3k/modules/SceHttp/SceHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ EXPORT(SceInt, sceHttpCreateConnectionWithURL, SceInt tmplId, const char *url, S
}
case SCE_HTTP_ERROR_OUT_OF_SIZE: return RET_ERROR(SCE_HTTP_ERROR_OUT_OF_SIZE);
default:
LOG_WARN("Returning missing case of parse_url {}", (int)parseRet);
LOG_WARN("Returning missing case of parse_url {}", static_cast<int>(parseRet));
assert(false);
return parseRet;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ EXPORT(SceInt, sceHttpCreateConnectionWithURL, SceInt tmplId, const char *url, S

long verify_flag = SSL_get_verify_result((SSL *)tmpl->second.ssl);
if (verify_flag != X509_V_OK && verify_flag != X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)
LOG_ERROR("Certificate verification error ({}) but continuing...\n", (int)verify_flag);
LOG_ERROR("Certificate verification error ({}) but continuing...\n", static_cast<int>(verify_flag));
}

emuenv.http.connections.emplace(connId, SceConnection{ tmplId, urlStr, enableKeepalive, isSecure, sockfd });
Expand Down Expand Up @@ -411,7 +411,7 @@ EXPORT(SceInt, sceHttpCreateRequestWithURL, SceInt connId, SceHttpMethods method
}
case SCE_HTTP_ERROR_OUT_OF_SIZE: return RET_ERROR(SCE_HTTP_ERROR_OUT_OF_SIZE);
default:
LOG_WARN("Returning missing case of parse_url {}", (int)parseRet);
LOG_WARN("Returning missing case of parse_url {}", static_cast<int>(parseRet));
assert(false);
return parseRet;
}
Expand Down Expand Up @@ -1451,7 +1451,7 @@ EXPORT(SceInt, sceHttpUriParse, SceHttpUriElement *out, const char *srcUrl, Ptr<
}
case SCE_HTTP_ERROR_OUT_OF_SIZE: return RET_ERROR(SCE_HTTP_ERROR_OUT_OF_SIZE);
default:
LOG_WARN("Returning missing case of parse_url {}", (int)parseRet);
LOG_WARN("Returning missing case of parse_url {}", static_cast<int>(parseRet));
assert(false);
return parseRet;
}
Expand Down
2 changes: 1 addition & 1 deletion vita3k/modules/SceLibKernel/SceLibKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ EXPORT(Ptr<void>, sceClibMemcpy_safe, Ptr<void> dst, const Ptr<void> src, SceSiz
CALL_EXPORT(sceClibMemcpy, dst, src.get(emuenv.mem), len);
return dst;
}
const auto diff = std::abs((int)(src.address() - dst.address()));
const auto diff = std::abs(static_cast<int>(src.address() - dst.address()));
if (len > diff) {
LOG_ERROR("sceClibMemcpy({},{},{}) src/dst overlap", log_hex_full(src.address()), log_hex_full(dst.address()), len);
assert(false);
Expand Down
2 changes: 1 addition & 1 deletion vita3k/modules/SceNet/SceNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ EXPORT(int, sceNetResolverGetError) {

EXPORT(int, sceNetResolverStartAton, int rid, const SceNetInAddr *addr, char *hostname, int len, int timeout, int retry, int flags) {
TRACY_FUNC(sceNetResolverStartAton, rid, addr, hostname, len, timeout, retry, flags);
struct hostent *resolved = gethostbyaddr((const char *)addr, len, AF_INET);
struct hostent *resolved = gethostbyaddr(reinterpret_cast<const char *>(addr), len, AF_INET);
strcpy(hostname, resolved->h_name);
return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions vita3k/net/src/posixsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ int PosixSocket::get_socket_options(int level, int optname, void *optval, unsign
CASE_GETSOCKOPT_VALUE(SCE_NET_SO_USECRYPTO, sockopt_so_usecrypto);
CASE_GETSOCKOPT_VALUE(SCE_NET_SO_USESIGNATURE, sockopt_so_usesignature);
CASE_GETSOCKOPT_VALUE(SCE_NET_SO_TPPOLICY, sockopt_so_tppolicy);
CASE_GETSOCKOPT_VALUE(SCE_NET_SO_NAME, (char)0); // writes an empty string to the output buffer
CASE_GETSOCKOPT_VALUE(SCE_NET_SO_NAME, static_cast<char>(0)); // writes an empty string to the output buffer
}
} else if (level == IPPROTO_IP) {
switch (optname) {
Expand Down Expand Up @@ -346,22 +346,22 @@ int PosixSocket::get_socket_options(int level, int optname, void *optval, unsign
int PosixSocket::recv_packet(void *buf, unsigned int len, int flags, SceNetSockaddr *from, unsigned int *fromlen) {
if (from != nullptr) {
sockaddr addr;
int res = recvfrom(sock, (char *)buf, len, flags, &addr, (socklen_t *)fromlen);
int res = recvfrom(sock, static_cast<char *>(buf), len, flags, &addr, (socklen_t *)fromlen);
convertPosixSockaddrToSce(&addr, from);
*fromlen = sizeof(SceNetSockaddrIn);

return translate_return_value(res);
} else {
return translate_return_value(recv(sock, (char *)buf, len, flags));
return translate_return_value(recv(sock, static_cast<char *>(buf), len, flags));
}
}

int PosixSocket::send_packet(const void *msg, unsigned int len, int flags, const SceNetSockaddr *to, unsigned int tolen) {
if (to != nullptr) {
sockaddr addr;
convertSceSockaddrToPosix(to, &addr);
return translate_return_value(sendto(sock, (const char *)msg, len, flags, &addr, sizeof(sockaddr_in)));
return translate_return_value(sendto(sock, static_cast<const char *>(msg), len, flags, &addr, sizeof(sockaddr_in)));
} else {
return translate_return_value(send(sock, (const char *)msg, len, flags));
return translate_return_value(send(sock, static_cast<const char *>(msg), len, flags));
}
}
6 changes: 3 additions & 3 deletions vita3k/np/src/trophy/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ bool Context::load_trophy_progress_file(const SceUID &progress_input_file) {
return false;

// Read trophy count by group
if (read_stuff(trophy_count_by_group.data(), (std::uint32_t)trophy_count_by_group.size() * 4) != (int)trophy_count_by_group.size() * 4)
if (read_stuff(trophy_count_by_group.data(), static_cast<std::uint32_t>(trophy_count_by_group.size()) * 4) != static_cast<int>(trophy_count_by_group.size()) * 4)
return false;

// Read timestamps
if (read_stuff(unlock_timestamps.data(), (std::uint32_t)unlock_timestamps.size() * 8) != (int)unlock_timestamps.size() * 8)
if (read_stuff(unlock_timestamps.data(), static_cast<std::uint32_t>(unlock_timestamps.size()) * 8) != static_cast<int>(unlock_timestamps.size()) * 8)
return false;

// Read trophy type (shinyyyy!! *yes this is lord of the ring reference*)
if (read_stuff(trophy_kinds.data(), (std::uint32_t)trophy_kinds.size() * 4) != (int)trophy_kinds.size() * 4)
if (read_stuff(trophy_kinds.data(), static_cast<std::uint32_t>(trophy_kinds.size()) * 4) != static_cast<int>(trophy_kinds.size()) * 4)
return false;

return true;
Expand Down
2 changes: 1 addition & 1 deletion vita3k/packages/src/license.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool open_license(const fs::path &license_path, SceNpDrmLicense &license_
memset(&license_buf, 0, sizeof(SceNpDrmLicense));
fs::ifstream license(license_path, std::ios::in | std::ios::binary);
if (license.is_open()) {
license.read((char *)&license_buf, sizeof(SceNpDrmLicense));
license.read(reinterpret_cast<char *>(&license_buf), sizeof(SceNpDrmLicense));
license.close();
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions vita3k/packages/src/pkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool install_pkg(const fs::path &pkg_path, EmuEnvState &emuenv, std::string &p_z
for (uint32_t i = 0; i < byte_swap(pkg_header.info_count); i++) {
uint32_t block[4];
infile.seekg(info_offset);
infile.read((char *)block, sizeof(block));
infile.read(reinterpret_cast<char *>(block), sizeof(block));

auto type = byte_swap(block[0]);
auto size = byte_swap(block[1]);
Expand Down Expand Up @@ -202,7 +202,7 @@ bool install_pkg(const fs::path &pkg_path, EmuEnvState &emuenv, std::string &p_z
std::vector<uint8_t> sfo_buffer(sfo_size);
SfoFile sfo_file;
infile.seekg(sfo_offset);
infile.read((char *)&sfo_buffer[0], sfo_size);
infile.read(reinterpret_cast<char *>(&sfo_buffer[0]), sfo_size);
sfo::load(sfo_file, sfo_buffer);
sfo::get_param_info(emuenv.app_info, sfo_buffer, emuenv.cfg.sys_lang);

Expand Down Expand Up @@ -259,11 +259,11 @@ bool install_pkg(const fs::path &pkg_path, EmuEnvState &emuenv, std::string &p_z
evp_cleanup();
return false;
}
const auto file_count = (float)byte_swap(pkg_header.file_count);
const auto file_count = static_cast<float>(byte_swap(pkg_header.file_count));
progress_callback(i / file_count * 100.f * 0.6f);
std::vector<unsigned char> name(byte_swap(entry.name_size));
infile.seekg(byte_swap(pkg_header.data_offset) + byte_swap(entry.name_offset));
infile.read((char *)&name[0], byte_swap(entry.name_size));
infile.read(reinterpret_cast<char *>(&name[0]), byte_swap(entry.name_size));

decrypt_aes_ctr(byte_swap(entry.name_offset) / 16, name.data(), byte_swap(entry.name_size));

Expand Down
4 changes: 2 additions & 2 deletions vita3k/packages/src/pup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static void decrypt_segments(std::ifstream &infile, const fs::path &outdir, cons
fs::ofstream outfile(outdir / fs_utils::path_concat(filename, ".seg02"), std::ios::binary);
infile.seekg(sceseg.offset);
std::vector<unsigned char> encrypted_data(sceseg.size);
infile.read((char *)&encrypted_data[0], sceseg.size);
infile.read(reinterpret_cast<char *>(&encrypted_data[0]), sceseg.size);

std::vector<unsigned char> decrypted_data(sceseg.size);
EVP_DecryptInit_ex(cipher_ctx, cipher, nullptr, reinterpret_cast<const unsigned char *>(sceseg.key.c_str()), reinterpret_cast<const unsigned char *>(sceseg.iv.c_str()));
Expand All @@ -195,7 +195,7 @@ static void decrypt_segments(std::ifstream &infile, const fs::path &outdir, cons
const std::string decompressed_data = decompress_segments(decrypted_data, sceseg.size);
outfile.write(decompressed_data.c_str(), decompressed_data.size());
} else {
outfile.write((char *)&decrypted_data[0], sceseg.size);
outfile.write(reinterpret_cast<char *>(&decrypted_data[0]), sceseg.size);
}
outfile.close();
}
Expand Down
Loading

0 comments on commit 6553ce2

Please sign in to comment.