diff --git a/include/hyprutils/math/Vector2D.hpp b/include/hyprutils/math/Vector2D.hpp index 4cc0402..f59e1e6 100644 --- a/include/hyprutils/math/Vector2D.hpp +++ b/include/hyprutils/math/Vector2D.hpp @@ -102,7 +102,7 @@ namespace Hyprutils { } // absolutely ridiculous formatter spec parsing -#define AQ_FORMAT_PARSE(specs__, type__) \ +#define AQ_FORMAT_PARSE(specs__, type__) \ template \ constexpr auto parse(FormatContext& ctx) { \ auto it = ctx.begin(); \ @@ -112,10 +112,10 @@ namespace Hyprutils { return it; \ } -#define AQ_FORMAT_FLAG(spec__, flag__) \ +#define AQ_FORMAT_FLAG(spec__, flag__) \ case spec__: (flag__) = true; break; -#define AQ_FORMAT_NUMBER(buf__) \ +#define AQ_FORMAT_NUMBER(buf__) \ case '0': \ case '1': \ case '2': \ @@ -139,9 +139,9 @@ struct std::formatter : std::formatter bool formatX = false; std::string precision = ""; AQ_FORMAT_PARSE(AQ_FORMAT_FLAG('j', formatJson) // - AQ_FORMAT_FLAG('X', formatX) // - AQ_FORMAT_NUMBER(precision), - Hyprutils::Math::Vector2D) + AQ_FORMAT_FLAG('X', formatX) // + AQ_FORMAT_NUMBER(precision), + Hyprutils::Math::Vector2D) template auto format(const Hyprutils::Math::Vector2D& vec, FormatContext& ctx) const { diff --git a/include/hyprutils/string/String.hpp b/include/hyprutils/string/String.hpp index 6490d07..cdc5c39 100644 --- a/include/hyprutils/string/String.hpp +++ b/include/hyprutils/string/String.hpp @@ -5,7 +5,7 @@ namespace Hyprutils { namespace String { // trims beginning and end of whitespace characters std::string trim(const std::string& in); - bool isNumber(const std::string& str, bool allowfloat = false); - void replaceInString(std::string& string, const std::string& what, const std::string& to); + bool isNumber(const std::string& str, bool allowfloat = false); + void replaceInString(std::string& string, const std::string& what, const std::string& to); }; }; \ No newline at end of file diff --git a/src/math/Box.cpp b/src/math/Box.cpp index fcd1eda..3cf503c 100644 --- a/src/math/Box.cpp +++ b/src/math/Box.cpp @@ -200,7 +200,7 @@ Vector2D Hyprutils::Math::CBox::size() const { } Vector2D Hyprutils::Math::CBox::extent() const { - return pos() + size(); + return pos() + size(); } Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const { diff --git a/src/os/Process.cpp b/src/os/Process.cpp index e5f20e1..7eebbba 100644 --- a/src/os/Process.cpp +++ b/src/os/Process.cpp @@ -86,14 +86,8 @@ bool Hyprutils::OS::CProcess::runSync() { return false; pollfd pollfds[2] = { - { - .fd = outPipe[0], - .events = POLLIN, - }, - { - .fd = errPipe[0], - .events = POLLIN, - }, + {.fd = outPipe[0], .events = POLLIN, .revents = 0}, + {.fd = errPipe[0], .events = POLLIN, .revents = 0}, }; while (1337) { @@ -188,26 +182,33 @@ bool Hyprutils::OS::CProcess::runAsync() { std::vector argsC; argsC.emplace_back(strdup(binary.c_str())); for (auto& arg : args) { - // TODO: does this leak? Can we just pipe c_str() as the strings won't be realloc'd? argsC.emplace_back(strdup(arg.c_str())); } argsC.emplace_back(nullptr); execvp(binary.c_str(), (char* const*)argsC.data()); - // exit grandchild _exit(0); } close(socket[0]); - write(socket[1], &grandchild, sizeof(grandchild)); + if (write(socket[1], &grandchild, sizeof(grandchild)) != sizeof(grandchild)) { + close(socket[1]); + _exit(1); + } close(socket[1]); - // exit child _exit(0); } + // run in parent close(socket[1]); - read(socket[0], &grandchild, sizeof(grandchild)); + ssize_t bytesRead = read(socket[0], &grandchild, sizeof(grandchild)); close(socket[0]); + + if (bytesRead != sizeof(grandchild)) { + waitpid(child, nullptr, 0); + return false; + } + // clear child and leave grandchild to init waitpid(child, nullptr, 0); diff --git a/src/signal/Signal.cpp b/src/signal/Signal.cpp index 3442fe7..e4771f9 100644 --- a/src/signal/Signal.cpp +++ b/src/signal/Signal.cpp @@ -27,7 +27,7 @@ void Hyprutils::Signal::CSignal::emit(std::any data) { // vector and was removed during our iteration if (l.strongRef() == 1) continue; - + l->emit(data); } @@ -38,7 +38,7 @@ void Hyprutils::Signal::CSignal::emit(std::any data) { // release SPs listeners.clear(); - // we cannot release any expired refs here as one of the listeners could've removed this object and + // we cannot release any expired refs here as one of the listeners could've removed this object and // as such we'd be doing a UAF } @@ -48,7 +48,7 @@ CHyprSignalListener Hyprutils::Signal::CSignal::registerListener(std::function