mirror of
https://github.com/decompals/wibo.git
synced 2025-10-16 07:05:11 +00:00
Cleanup various lints and warnings
This commit is contained in:
parent
9cd15e9be8
commit
3078cef12b
@ -10,7 +10,7 @@
|
|||||||
- `cmake --build --preset debug` compiles the program and tests.
|
- `cmake --build --preset debug` compiles the program and tests.
|
||||||
- `./build/debug/wibo /path/to/program.exe` runs a Windows binary. Use `-D` (or `WIBO_DEBUG=1`) for verbose logging. Use `-C` to set the working directory.
|
- `./build/debug/wibo /path/to/program.exe` runs a Windows binary. Use `-D` (or `WIBO_DEBUG=1`) for verbose logging. Use `-C` to set the working directory.
|
||||||
- `ctest --preset fixtures` runs the self-checking WinAPI fixtures (requires `i686-w64-mingw32-gcc` and `i686-w64-mingw32-windres`).
|
- `ctest --preset fixtures` runs the self-checking WinAPI fixtures (requires `i686-w64-mingw32-gcc` and `i686-w64-mingw32-windres`).
|
||||||
- `clang-format -i path/to/file.cpp` and `clang-tidy path/to/file.cpp -p build` keep contributions aligned with the repo's tooling.
|
- `clang-format -i path/to/file.cpp` and `clang-tidy -p build/debug path/to/file.cpp` keep contributions aligned with the repo's tooling.
|
||||||
|
|
||||||
## Coding Style & Naming Conventions
|
## Coding Style & Naming Conventions
|
||||||
- Formatting follows `.clang-format` (LLVM base, tabbed indentation width 4, 120 column limit).
|
- Formatting follows `.clang-format` (LLVM base, tabbed indentation width 4, 120 column limit).
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "errors.h"
|
|
||||||
|
|
||||||
namespace kernel32 {
|
namespace kernel32 {
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ struct ProcessObject final : WaitableObject {
|
|||||||
static constexpr ObjectType kType = ObjectType::Process;
|
static constexpr ObjectType kType = ObjectType::Process;
|
||||||
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
pid_t tid;
|
pid_t tid = 0;
|
||||||
int pidfd;
|
int pidfd;
|
||||||
DWORD exitCode = STILL_ACTIVE;
|
DWORD exitCode = STILL_ACTIVE;
|
||||||
bool forcedExitCode = false;
|
bool forcedExitCode = false;
|
||||||
|
@ -315,9 +315,9 @@ int WIN_FUNC LCMapStringW(LCID Locale, DWORD dwMapFlags, LPCWCH lpSrcStr, int cc
|
|||||||
for (size_t i = 0; i < srcLen; ++i) {
|
for (size_t i = 0; i < srcLen; ++i) {
|
||||||
uint16_t ch = lpSrcStr[i];
|
uint16_t ch = lpSrcStr[i];
|
||||||
if (casingFlags == 0x00000200u) {
|
if (casingFlags == 0x00000200u) {
|
||||||
buffer[i] = static_cast<uint16_t>(std::towupper(static_cast<wint_t>(ch)));
|
buffer[i] = wcharToUpper(ch);
|
||||||
} else if (casingFlags == 0x00000100u) {
|
} else if (casingFlags == 0x00000100u) {
|
||||||
buffer[i] = static_cast<uint16_t>(std::towlower(static_cast<wint_t>(ch)));
|
buffer[i] = wcharToLower(ch);
|
||||||
} else {
|
} else {
|
||||||
buffer[i] = ch;
|
buffer[i] = ch;
|
||||||
}
|
}
|
||||||
|
@ -2150,8 +2150,7 @@ namespace msvcrt {
|
|||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
wchar_t ch = static_cast<wchar_t>(str[i]);
|
str[i] = wcharToUpper(str[i]);
|
||||||
str[i] = static_cast<uint16_t>(std::towupper(ch));
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2167,8 +2166,7 @@ namespace msvcrt {
|
|||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
wchar_t ch = static_cast<wchar_t>(str[i]);
|
str[i] = wcharToLower(str[i]);
|
||||||
str[i] = static_cast<uint16_t>(std::towlower(ch));
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2176,7 +2174,7 @@ namespace msvcrt {
|
|||||||
wint_t WIN_ENTRY towlower(wint_t ch) {
|
wint_t WIN_ENTRY towlower(wint_t ch) {
|
||||||
HOST_CONTEXT_GUARD();
|
HOST_CONTEXT_GUARD();
|
||||||
VERBOSE_LOG("towlower(%d)\n", ch);
|
VERBOSE_LOG("towlower(%d)\n", ch);
|
||||||
return static_cast<wint_t>(std::towlower(static_cast<wchar_t>(ch)));
|
return wcharToLower(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WIN_ENTRY _mbctolower(unsigned int ch) {
|
unsigned int WIN_ENTRY _mbctolower(unsigned int ch) {
|
||||||
@ -2416,9 +2414,8 @@ namespace msvcrt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto wStr = stringToWideString(wibo::guestExecutablePath.c_str());
|
const auto wStr = stringToWideString(wibo::guestExecutablePath.c_str());
|
||||||
if (_wpgmptr) {
|
delete[] _wpgmptr;
|
||||||
delete[] _wpgmptr;
|
|
||||||
}
|
|
||||||
_wpgmptr = new uint16_t[wStr.size() + 1];
|
_wpgmptr = new uint16_t[wStr.size() + 1];
|
||||||
std::copy(wStr.begin(), wStr.end(), _wpgmptr);
|
std::copy(wStr.begin(), wStr.end(), _wpgmptr);
|
||||||
_wpgmptr[wStr.size()] = 0;
|
_wpgmptr[wStr.size()] = 0;
|
||||||
@ -2660,7 +2657,7 @@ namespace msvcrt {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WIN_ENTRY wcscpy_s(uint16_t *dest, size_t dest_size, const uint16_t *src){
|
int WIN_ENTRY wcscpy_s(uint16_t *dest, size_t dest_size, const uint16_t *src) {
|
||||||
HOST_CONTEXT_GUARD();
|
HOST_CONTEXT_GUARD();
|
||||||
std::string src_str = wideStringToString(src);
|
std::string src_str = wideStringToString(src);
|
||||||
VERBOSE_LOG("wcscpy_s(%p, %zu, %p)\n", dest, dest_size, src);
|
VERBOSE_LOG("wcscpy_s(%p, %zu, %p)\n", dest, dest_size, src);
|
||||||
@ -2753,37 +2750,60 @@ namespace msvcrt {
|
|||||||
return wstrncmp(string1, string2, count);
|
return wstrncmp(string1, string2, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WIN_ENTRY _vswprintf_c_l(uint16_t* buffer, size_t size, const uint16_t* format, ...) {
|
int WIN_ENTRY _vswprintf_c_l(uint16_t *buffer, size_t size, const uint16_t *format, ...) {
|
||||||
HOST_CONTEXT_GUARD();
|
HOST_CONTEXT_GUARD();
|
||||||
DEBUG_LOG("_vswprintf_c_l(%p, %zu, %p, ...)\n", buffer, size, format);
|
DEBUG_LOG("_vswprintf_c_l(%p, %zu, %p, ...)\n", buffer, size, format);
|
||||||
if (!buffer || !format || size == 0)
|
if (!buffer || !format || size == 0) {
|
||||||
|
if (buffer && size > 0) {
|
||||||
|
buffer[0] = 0;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
std::string narrow_fmt = wideStringToString(format);
|
std::string narrow_fmt = wideStringToString(format);
|
||||||
DEBUG_LOG("\tFmt: %s\n", narrow_fmt.c_str());
|
DEBUG_LOG("\tFmt: %s\n", narrow_fmt.c_str());
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
int required = vsnprintf(nullptr, 0, narrow_fmt.c_str(), args);
|
va_list argsCopy;
|
||||||
va_end(args);
|
va_copy(argsCopy, args);
|
||||||
|
int required = vsnprintf(nullptr, 0, narrow_fmt.c_str(), argsCopy);
|
||||||
|
va_end(argsCopy);
|
||||||
|
|
||||||
if (required < 0) {
|
if (required < 0) {
|
||||||
|
va_end(args);
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer_narrow[required + 1];
|
std::vector<char> narrowBuffer(static_cast<size_t>(required) + 1);
|
||||||
va_start(args, format);
|
int written = vsnprintf(narrowBuffer.data(), narrowBuffer.size(), narrow_fmt.c_str(), args);
|
||||||
vsnprintf(buffer_narrow, required + 1, narrow_fmt.c_str(), args);
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
DEBUG_LOG("\tBuffer: %s\n", buffer_narrow);
|
|
||||||
|
|
||||||
std::vector<uint16_t> wide = stringToWideString(buffer_narrow);
|
if (written < 0) {
|
||||||
size_t copy_len = std::min(wide.size(), size - 1);
|
buffer[0] = 0;
|
||||||
std::memcpy(buffer, wide.data(), copy_len * sizeof(uint16_t));
|
return -1;
|
||||||
buffer[copy_len] = 0;
|
}
|
||||||
|
DEBUG_LOG("\tBuffer: %s\n", narrowBuffer.data());
|
||||||
|
|
||||||
return static_cast<int>(copy_len);
|
std::vector<uint16_t> wide = stringToWideString(narrowBuffer.data());
|
||||||
// return vswprintf(buffer, size, format, args); this doesn't work because on this architecture, wchar_t is size 4, instead of size 2
|
size_t wideLen = wide.size();
|
||||||
|
|
||||||
|
if (wideLen + 1 > size) {
|
||||||
|
buffer[0] = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (wideLen > static_cast<size_t>(std::numeric_limits<int>::max())) {
|
||||||
|
buffer[0] = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wideLen > 0) {
|
||||||
|
std::memcpy(buffer, wide.data(), wideLen * sizeof(uint16_t));
|
||||||
|
}
|
||||||
|
buffer[wideLen] = 0;
|
||||||
|
|
||||||
|
return static_cast<int>(wideLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint16_t* WIN_ENTRY wcsstr( const uint16_t *dest, const uint16_t *src ){
|
const uint16_t* WIN_ENTRY wcsstr( const uint16_t *dest, const uint16_t *src ){
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#define PIO_APC_ROUTINE void *
|
using PIO_APC_ROUTINE = void *;
|
||||||
|
|
||||||
typedef struct _IO_STATUS_BLOCK {
|
typedef struct _IO_STATUS_BLOCK {
|
||||||
union {
|
union {
|
||||||
@ -109,7 +109,7 @@ std::string windowsImagePathFor(const ProcessHandleDetails &details) {
|
|||||||
if (!ec) {
|
if (!ec) {
|
||||||
return files::pathToWindows(files::canonicalPath(resolved));
|
return files::pathToWindows(files::canonicalPath(resolved));
|
||||||
}
|
}
|
||||||
return std::string();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -16,11 +16,11 @@ namespace {
|
|||||||
|
|
||||||
constexpr uint32_t RT_VERSION = 16;
|
constexpr uint32_t RT_VERSION = 16;
|
||||||
|
|
||||||
static uint16_t readU16(const uint8_t *ptr) { return static_cast<uint16_t>(ptr[0] | (ptr[1] << 8)); }
|
uint16_t readU16(const uint8_t *ptr) { return static_cast<uint16_t>(ptr[0] | (ptr[1] << 8)); }
|
||||||
|
|
||||||
static size_t align4(size_t offset) { return (offset + 3u) & ~static_cast<size_t>(3u); }
|
size_t align4(size_t offset) { return (offset + 3u) & ~static_cast<size_t>(3u); }
|
||||||
|
|
||||||
static std::string narrowKey(const std::u16string &key) {
|
std::string narrowKey(const std::u16string &key) {
|
||||||
std::string result;
|
std::string result;
|
||||||
result.reserve(key.size());
|
result.reserve(key.size());
|
||||||
for (char16_t ch : key) {
|
for (char16_t ch : key) {
|
||||||
@ -40,7 +40,7 @@ struct VersionBlockView {
|
|||||||
uint32_t childrenBytes = 0;
|
uint32_t childrenBytes = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool parseVersionBlock(const uint8_t *block, size_t available, VersionBlockView &out) {
|
bool parseVersionBlock(const uint8_t *block, size_t available, VersionBlockView &out) {
|
||||||
if (available < sizeof(uint16_t) * 3) {
|
if (available < sizeof(uint16_t) * 3) {
|
||||||
DEBUG_LOG("header too small: available=%zu\n", available);
|
DEBUG_LOG("header too small: available=%zu\n", available);
|
||||||
return false;
|
return false;
|
||||||
@ -99,8 +99,8 @@ static bool parseVersionBlock(const uint8_t *block, size_t available, VersionBlo
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool queryVersionBlock(const uint8_t *block, size_t available, const std::vector<std::string> &segments,
|
bool queryVersionBlock(const uint8_t *block, size_t available, const std::vector<std::string> &segments, size_t depth,
|
||||||
size_t depth, const uint8_t **outPtr, uint32_t *outLen, uint16_t *outType) {
|
const uint8_t **outPtr, uint32_t *outLen, uint16_t *outType) {
|
||||||
VersionBlockView view;
|
VersionBlockView view;
|
||||||
if (!parseVersionBlock(block, available, view))
|
if (!parseVersionBlock(block, available, view))
|
||||||
return false;
|
return false;
|
||||||
@ -139,7 +139,7 @@ static bool queryVersionBlock(const uint8_t *block, size_t available, const std:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool splitSubBlock(const std::string &subBlock, std::vector<std::string> &segments) {
|
bool splitSubBlock(const std::string &subBlock, std::vector<std::string> &segments) {
|
||||||
segments.clear();
|
segments.clear();
|
||||||
if (subBlock.empty() || subBlock == "\\")
|
if (subBlock.empty() || subBlock == "\\")
|
||||||
return true;
|
return true;
|
||||||
@ -158,7 +158,7 @@ static bool splitSubBlock(const std::string &subBlock, std::vector<std::string>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool loadVersionResource(const char *fileName, std::vector<uint8_t> &buffer) {
|
bool loadVersionResource(const char *fileName, std::vector<uint8_t> &buffer) {
|
||||||
if (!fileName) {
|
if (!fileName) {
|
||||||
wibo::lastError = ERROR_INVALID_PARAMETER;
|
wibo::lastError = ERROR_INVALID_PARAMETER;
|
||||||
return false;
|
return false;
|
||||||
|
@ -36,14 +36,26 @@ uint16_t wcharToLower(uint16_t ch) {
|
|||||||
if (ch >= 'A' && ch <= 'Z') {
|
if (ch >= 'A' && ch <= 'Z') {
|
||||||
return static_cast<uint16_t>(ch + ('a' - 'A'));
|
return static_cast<uint16_t>(ch + ('a' - 'A'));
|
||||||
}
|
}
|
||||||
wchar_t wide = static_cast<wchar_t>(ch);
|
wint_t wide = static_cast<wint_t>(ch);
|
||||||
wchar_t lowered = std::towlower(wide);
|
wint_t lowered = std::towlower(wide);
|
||||||
if (lowered < 0 || lowered > 0xFFFF) {
|
if (lowered > 0xFFFF) {
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
return static_cast<uint16_t>(lowered);
|
return static_cast<uint16_t>(lowered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t wcharToUpper(uint16_t ch) {
|
||||||
|
if (ch >= 'a' && ch <= 'z') {
|
||||||
|
return static_cast<uint16_t>(ch - ('a' - 'A'));
|
||||||
|
}
|
||||||
|
wint_t wide = static_cast<wint_t>(ch);
|
||||||
|
wint_t uppered = std::towupper(wide);
|
||||||
|
if (uppered > 0xFFFF) {
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
return static_cast<uint16_t>(uppered);
|
||||||
|
}
|
||||||
|
|
||||||
size_t wstrlen(const uint16_t *str) {
|
size_t wstrlen(const uint16_t *str) {
|
||||||
if (!str)
|
if (!str)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -24,3 +24,4 @@ void toUpperInPlace(std::string &str);
|
|||||||
std::string stringToLower(std::string_view str);
|
std::string stringToLower(std::string_view str);
|
||||||
std::string stringToUpper(std::string_view str);
|
std::string stringToUpper(std::string_view str);
|
||||||
uint16_t wcharToLower(uint16_t ch);
|
uint16_t wcharToLower(uint16_t ch);
|
||||||
|
uint16_t wcharToUpper(uint16_t ch);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user