From d5d7cfb291c24178f912a5b790f76625f7f45138 Mon Sep 17 00:00:00 2001 From: Eduard Bloch Date: Sat, 5 Oct 2024 12:36:28 +0200 Subject: [PATCH 1/2] Solve some warnings from receng clang and gcc - also blanking the string memory buffer is not needed, simplified that. - fix ambigous != operator (for C++20 standard) --- src/aapm.cc | 6 +----- src/mstring.cc | 9 ++++----- src/wmswitch.cc | 1 + src/yscrollview.cc | 4 ++-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/aapm.cc b/src/aapm.cc index 70c534884..8bb5bc13c 100644 --- a/src/aapm.cc +++ b/src/aapm.cc @@ -278,7 +278,6 @@ void YApm::AcpiStr(char *s, bool Tool) { acIsOnLine = (ACstatus == AC_ONLINE); energyFull = energyNow = 0; - int batCount = 0; int n = 0; for (int i = 0; i < batteryNum; i++) { @@ -422,7 +421,6 @@ void YApm::AcpiStr(char *s, bool Tool) { { energyFull += BATcapacity_full; energyNow += BATcapacity_remain; - batCount++; } bat_info[0] = 0; @@ -660,7 +658,6 @@ void YApm::PmuStr(char *s, const bool tool_tip) fclose(fd); acIsOnLine = (power_present != 0); - int batCount = 0; char* s_end = s; for (int i = 0; i < batteryNum; ++i) { @@ -701,7 +698,6 @@ void YApm::PmuStr(char *s, const bool tool_tip) { energyFull += max_charge; energyNow += charge; - batCount++; } if (tool_tip) { @@ -949,7 +945,7 @@ bool YApm::updateState() { } bool YApm::picture() { - bool update = (hasPixmap() == false); + bool update = !hasPixmap(); if (update || fStatusChanged) { Pixmap pixmap(IApplet::getPixmap()); if (pixmap) { diff --git a/src/mstring.cc b/src/mstring.cc index e1a09d238..74033692f 100644 --- a/src/mstring.cc +++ b/src/mstring.cc @@ -22,10 +22,9 @@ void MStringRef::create(const char* str, size_t len) { if (len) { alloc(len); if (str) { - strncpy(fStr->fStr, str, len); - fStr->fStr[len] = 0; + strncpy(fStr->fStr, str, len + 1); } else { - memset(fStr->fStr, 0, len + 1); + fStr->fStr[0]=0; } } else { fStr = nullptr; @@ -45,9 +44,9 @@ mstring::mstring(const char* str1, size_t len1, const char* str2, size_t len2): { if (fRef) { if (len1) - strncpy(fRef->fStr, str1, len1); + strncpy(fRef->fStr, str1, len1 + 1); if (len2) - strncpy(fRef->fStr + len1, str2, len2); + strncpy(fRef->fStr + len1, str2, len2 + 1); fRef[fCount] = 0; fRef.acquire(); } diff --git a/src/wmswitch.cc b/src/wmswitch.cc index fae3e4ca0..401f30f55 100644 --- a/src/wmswitch.cc +++ b/src/wmswitch.cc @@ -29,6 +29,7 @@ struct ZItem { bool operator==(YFrameWindow* f) const { return f == frame && f; } bool operator==(YFrameClient* c) const { return c == client && c; } bool operator==(bool b) const { return bool(*this) == b; } + bool operator!=(bool b) const { return bool(*this) != b; } bool operator!() const { return bool(*this) == false; } static int compare(const void* p1, const void* p2) { diff --git a/src/yscrollview.cc b/src/yscrollview.cc index e31a33f52..24350ab5d 100644 --- a/src/yscrollview.cc +++ b/src/yscrollview.cc @@ -77,8 +77,8 @@ void YScrollView::configure(const YRect2& r) { } bool YScrollView::handleScrollKeys(const XKeyEvent& key) { - return scrollVert->handleScrollKeys(key) - | scrollHoriz->handleScrollKeys(key); + return int(scrollVert->handleScrollKeys(key)) + | int(scrollHoriz->handleScrollKeys(key)); } void YScrollView::handleExpose(const XExposeEvent& expose) { From 9c77c3bfb2145cbbcfaf3802fdfcfe85306848cf Mon Sep 17 00:00:00 2001 From: Eduard Bloch Date: Sat, 5 Oct 2024 23:18:43 +0200 Subject: [PATCH 2/2] Stop using VLAs, they are not fully legal in C++ --- src/apppstatus.cc | 2 +- src/misc.cc | 3 ++- src/wmdock.cc | 2 +- src/wmmgr.cc | 2 +- src/wmpref.cc | 2 +- src/yarray.cc | 3 ++- src/yfontxft.cc | 5 +++-- src/yxtray.cc | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/apppstatus.cc b/src/apppstatus.cc index 22efde8b3..7585b455e 100644 --- a/src/apppstatus.cc +++ b/src/apppstatus.cc @@ -786,7 +786,7 @@ void NetStatusControl::linuxUpdate() { } int const count(fNetStatus.getCount()); - bool covered[count]; + asmart covered(new bool[count]); for (int i = 0; i < count; ++i) { covered[i] = (nullptr == fNetStatus[i]); } diff --git a/src/misc.cc b/src/misc.cc index e1ecc6e18..0098deed9 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -31,6 +31,7 @@ #include "intl.h" #include "ascii.h" +#include "ypointer.h" using namespace ASCII; @@ -736,7 +737,7 @@ int process_close(FILE* fp, int pid) { void show_backtrace(const int limit) { #if defined(HAVE_BACKTRACE_SYMBOLS_FD) && defined(HAVE_EXECINFO_H) const int asize = Elvis(limit, 20); - void *array[asize]; + asmart array(new void*[asize]); const int count = backtrace(array, asize); const char tool[] = "/usr/bin/addr2line"; char* prog = progpath(); diff --git a/src/wmdock.cc b/src/wmdock.cc index 56d5a1ecc..eebcf3671 100644 --- a/src/wmdock.cc +++ b/src/wmdock.cc @@ -357,7 +357,7 @@ void DockApp::proper() { if (intern) { const int count = docks.getCount(); if (count) { - Atom atoms[count]; + asmart atoms(new Atom[count]); for (int i = 0; i < count; ++i) { atoms[i] = Atom(docks[i].client->handle()); } diff --git a/src/wmmgr.cc b/src/wmmgr.cc index fbc6048c1..6316f69e3 100644 --- a/src/wmmgr.cc +++ b/src/wmmgr.cc @@ -3079,7 +3079,7 @@ void YWindowManager::setDesktopCount() { void YWindowManager::setDesktopViewport() { MSG(("setting: _NET_DESKTOP_VIEWPORT")); const int n = 2 * workspaceCount; - Atom data[n]; + asmart data(new Atom[n]); for (int i = 0; i < n; ++i) data[i] = 0; setProperty(_XA_NET_DESKTOP_VIEWPORT, XA_CARDINAL, data, n); diff --git a/src/wmpref.cc b/src/wmpref.cc index f95dabdda..0bfafe8e6 100644 --- a/src/wmpref.cc +++ b/src/wmpref.cc @@ -42,7 +42,7 @@ PrefsMenu::PrefsMenu() : addSubmenu("S_calar", -2, sc = new YMenu, "key"); addSubmenu("St_ring", -2, st = new YMenu, "key"); - int index[count]; + asmart index(new int[count]); for (int i = 0; i < count; ++i) { index[i] = i; } diff --git a/src/yarray.cc b/src/yarray.cc index 58dbffefc..32d2d295c 100644 --- a/src/yarray.cc +++ b/src/yarray.cc @@ -16,6 +16,7 @@ #include "config.h" #include "mstring.h" #include "yarray.h" +#include "ypointer.h" #include #include #include @@ -125,7 +126,7 @@ void YBaseArray::extend(const SizeType extendedCount) { void YBaseArray::moveto(const SizeType index, const SizeType place) { PRECONDITION(index < fCount); PRECONDITION(place < fCount); - unsigned char copy[fElementSize]; + asmart copy(new unsigned char[fElementSize]); memcpy(copy, getElement(index), fElementSize); if (index < place) { memmove(getElement(index), getElement(index + 1), diff --git a/src/yfontxft.cc b/src/yfontxft.cc index 4d09c9d33..6ef8461de 100644 --- a/src/yfontxft.cc +++ b/src/yfontxft.cc @@ -278,7 +278,8 @@ void YXftFont::drawLimitLeft(Graphics& g, XftFont* font, int x, int y, lo -= 1; if (0 < ew) { const int size = lo + 2; - wchar_t copy[size]; + asmart copy(new wchar_t[size]); + memcpy(copy, str, lo * sizeof(wchar_t)); copy[lo] = el; copy[lo + 1] = 0; @@ -310,7 +311,7 @@ void YXftFont::drawLimitRight(Graphics& g, XftFont* font, int x, int y, } if (0 < ew) { const int size = lo + 2; - wchar_t copy[size]; + asmart copy(new wchar_t[size]); memcpy(copy + 1, str + len - lo, lo * sizeof(wchar_t)); copy[0] = el; copy[lo + 1] = 0; diff --git a/src/yxtray.cc b/src/yxtray.cc index 725ab8726..6fc5ab19c 100644 --- a/src/yxtray.cc +++ b/src/yxtray.cc @@ -860,7 +860,7 @@ void YXTray::trayUpdateGeometry(unsigned w, unsigned h, bool visible) { void YXTray::updateTrayWindows() { const int count = fDocked.getCount(); - Window windows[count]; + asmart windows(new Window[count]); for (IterType ec = fDocked.iterator(); ++ec; ) windows[ec.where()] = ec->leader();