Skip to content

Commit

Permalink
lint by codacy, simplify PrintFmt()
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed Dec 14, 2024
1 parent 48c432e commit 21754b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,8 @@ class Filter {
public:
Filter() noexcept : name(nullptr), patterns() {}

Filter(const Filter& filter) {
name = filter.name;
patterns = filter.patterns;
}
Filter(const Filter& filter) :
name(filter.name), patterns(filter.patterns) {}

Filter& operator=(const Filter& filter) {
if (this == &filter) return *this;
Expand Down
22 changes: 8 additions & 14 deletions src/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,12 @@ void FprintFmt(FILE* out, const char* fmt, ...) noexcept {
va_end(va2);
n++;

char* buf = reinterpret_cast<char *>(uiprivAlloc(n * sizeof (char), "char[]"));
vsprintf_s(buf, n, fmt, va);
noex::string buf = noex::string(n);
vsprintf_s(buf.data(), buf.size(), fmt, va);
va_end(va);

WCHAR* wfmt = toUTF16(buf);
fwprintf(out, L"%ls", wfmt);

uiprivFree(buf);
uiprivFree(wfmt);
noex::wstring wbuf = UTF8toUTF16(buf.c_str());
fwprintf(out, L"%ls", wbuf.c_str());
}

// Enable ANSI escape sequences on the console window.
Expand Down Expand Up @@ -437,13 +434,10 @@ void FprintFmt(FILE* out, const char* fmt, ...) noexcept {
va_copy(va2, va);
size_t size = vsnprintf(NULL, 0, fmt, va2);
va_end(va2);
noex::string buf_str = noex::string(size);
if (noex::get_error_no() != noex::OK) return; // failed to allocate buffer
char* buf = buf_str.data();
buf[size] = 0;
vsnprintf(buf, size + 1, fmt, va);
g_logger.Log(buf);
fprintf(out, "%s", buf);
noex::string buf = noex::string(size + 1);
vsnprintf(buf.data(), buf.size(), fmt, va);
g_logger.Log(buf.c_str());
fprintf(out, "%s", buf.c_str());
va_end(va);
}
#endif
Expand Down

0 comments on commit 21754b9

Please sign in to comment.