Skip to content

Commit

Permalink
fix compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Oct 23, 2023
1 parent 0f47193 commit 9db87c0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Favorites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static FavTreeItem* MakeFavTopLevelItem(FileState* fav, bool isExpanded) {
text = FavCompactReadableNameTemp(fav, fn);
} else {
char* fp = fav->filePath;
text = path::GetBaseNameTemp(fp);
text = (TempStr)path::GetBaseNameTemp(fp);
}
res->text = str::Dup(text);
return res;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/BaseUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ using uint = unsigned int;

#define NoOp() ((void)0)
#define dimof(array) (sizeof(DimofSizeHelper(array)))
#define dimofi(array) (int)(sizeof(DimofSizeHelper(array)))

template <typename T, size_t N>
char (&DimofSizeHelper(T (&array)[N]))[N];

Expand Down
7 changes: 4 additions & 3 deletions src/utils/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,10 @@ bool RemoveAll(const char* dir) {
WCHAR* dirW = ToWStrTemp(dir);
// path must be doubly terminated
// https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shfileopstructa#fo_rename
size_t n = str::Len(dirW) + 2;
AutoFreeWstr dirDoubleTerminated = AllocArray<WCHAR>(n);
str::BufSet(dirDoubleTerminated, n, dirW);
auto n = str::Len(dirW) + 2;
auto a = GetTempAllocator();
TempWStr dirDoubleTerminated = (WCHAR*)Allocator::AllocZero(a, n * sizeof(WCHAR));
str::BufSet(dirDoubleTerminated,(int)n, dirW);
FILEOP_FLAGS flags = FOF_NO_UI;
uint op = FO_DELETE;
SHFILEOPSTRUCTW shfo = {nullptr, op, dirDoubleTerminated, nullptr, flags, FALSE, nullptr, nullptr};
Expand Down
24 changes: 16 additions & 8 deletions src/utils/StrUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,18 @@ size_t Len(const char* s) {
return s ? strlen(s) : 0;
}

int Leni(const char* s) {
return s ? (int)strlen(s) : 0;
}

size_t Len(const WCHAR* s) {
return s ? wcslen(s) : 0;
}

int Leni(const WCHAR* s) {
return s ? (int)wcslen(s) : 0;
}

void Free(const char* s) {
free((void*)s);
}
Expand Down Expand Up @@ -833,7 +841,7 @@ static const char* ParseLimitedNumber(const char* str, const char* format, const
const char* endF = Parse(format, "%u%c", &width, &f2[1]);
if (endF && FindChar("udx", f2[1]) && width <= Len(str)) {
char limited[16]; // 32-bit integers are at most 11 characters long
str::BufSet(limited, std::min((size_t)width + 1, dimof(limited)), str);
str::BufSet(limited, std::min((int)width + 1, dimofi(limited)), str);
const char* end = Parse(limited, f2, valueOut);
if (end && !*end) {
*endOut = str + width;
Expand Down Expand Up @@ -2213,7 +2221,7 @@ size_t NormalizeWSInPlace(WCHAR* str) {
int BufSet(char* dst, int dstCchSize, const char* src) {
CrashAlwaysIf(0 == dstCchSize);

int srcCchSize = str::Len(src);
int srcCchSize = (int)str::Len(src);
int toCopy = std::min(dstCchSize - 1, srcCchSize);

errno_t err = strncpy_s(dst, (size_t)dstCchSize, src, (size_t)toCopy);
Expand All @@ -2225,7 +2233,7 @@ int BufSet(char* dst, int dstCchSize, const char* src) {
int BufSet(WCHAR* dst, int dstCchSize, const WCHAR* src) {
CrashAlwaysIf(0 == dstCchSize);

int srcCchSize = str::Len(src);
int srcCchSize = str::Leni(src);
int toCopy = std::min(dstCchSize - 1, srcCchSize);

memset(dst, 0, dstCchSize * sizeof(WCHAR));
Expand All @@ -2240,12 +2248,12 @@ int BufSet(WCHAR* dst, int dstCchSize, const char* src) {
int BufAppend(WCHAR* dst, int dstCchSize, const WCHAR* s) {
CrashAlwaysIf(0 == dstCchSize);

int currDstCchLen = str::Len(dst);
int currDstCchLen = str::Leni(dst);
if (currDstCchLen + 1 >= dstCchSize) {
return 0;
}
int left = dstCchSize - currDstCchLen - 1;
int srcCchSize = str::Len(s);
int srcCchSize = str::Leni(s);
int toCopy = std::min(left, srcCchSize);

errno_t err = wcsncat_s(dst, dstCchSize, s, toCopy);
Expand All @@ -2259,12 +2267,12 @@ int BufAppend(WCHAR* dst, int dstCchSize, const WCHAR* s) {
int BufAppend(char* dst, int dstCchSize, const char* s) {
CrashAlwaysIf(0 == dstCchSize);

int currDstCchLen = str::Len(dst);
int currDstCchLen = str::Leni(dst);
if (currDstCchLen + 1 >= dstCchSize) {
return 0;
}
int left = dstCchSize - currDstCchLen - 1;
int srcCchSize = str::Len(s);
int srcCchSize = str::Leni(s);
int toCopy = std::min(left, srcCchSize);

errno_t err = strncat_s(dst, dstCchSize, s, toCopy);
Expand Down Expand Up @@ -2430,7 +2438,7 @@ static const WCHAR* ParseLimitedNumber(const WCHAR* str, const WCHAR* format, co
const WCHAR* endF = Parse(format, L"%u%c", &width, &f2[1]);
if (endF && FindChar(L"udx", f2[1]) && width <= Len(str)) {
WCHAR limited[16]; // 32-bit integers are at most 11 characters long
str::BufSet(limited, std::min((size_t)width + 1, dimof(limited)), str);
str::BufSet(limited, std::min((int)width + 1, dimofi(limited)), str);
const WCHAR* end = Parse(limited, f2, valueOut);
if (end && !*end) {
*endOut = str + width;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/StrUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ enum class TrimOpt { Left, Right, Both };
size_t Len(const WCHAR*);
size_t Len(const char* s);

int Leni(const WCHAR*);
int Leni(const char* s);

void Free(const char*);
void Free(const u8*);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/WinUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ static bool CopyOrAppendTextToClipboard(const WCHAR* text, bool appendOnly) {
EmptyClipboard();
}

size_t n = str::Len(text) + 1;
int n = str::Leni(text) + 1;
HGLOBAL handle = GlobalAlloc(GMEM_MOVEABLE, n * sizeof(WCHAR));
if (handle) {
WCHAR* globalText = (WCHAR*)GlobalLock(handle);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tests/StrUtil_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ void StrTest() {
};

for (int i = 0; i < dimof(formatRomanData); i++) {
TempStr tmp = str::FormatRomanNumeral(formatRomanData[i].number);
TempStr tmp = str::FormatRomanNumeralTemp(formatRomanData[i].number);
utassert(str::Eq(tmp, formatRomanData[i].result));
}

Expand Down

0 comments on commit 9db87c0

Please sign in to comment.