Skip to content

Commit

Permalink
Merge pull request #787 from Code7R/fix_clang_warnings
Browse files Browse the repository at this point in the history
Solve some warnings from receng clang and gcc
  • Loading branch information
Code7R authored Oct 6, 2024
2 parents cb210b7 + 9c77c3b commit d6bedaa
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/aapm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -422,7 +421,6 @@ void YApm::AcpiStr(char *s, bool Tool) {
{
energyFull += BATcapacity_full;
energyNow += BATcapacity_remain;
batCount++;
}

bat_info[0] = 0;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -701,7 +698,6 @@ void YApm::PmuStr(char *s, const bool tool_tip)
{
energyFull += max_charge;
energyNow += charge;
batCount++;
}

if (tool_tip) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/apppstatus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ void NetStatusControl::linuxUpdate() {
}

int const count(fNetStatus.getCount());
bool covered[count];
asmart<bool> covered(new bool[count]);
for (int i = 0; i < count; ++i) {
covered[i] = (nullptr == fNetStatus[i]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "intl.h"
#include "ascii.h"
#include "ypointer.h"

using namespace ASCII;

Expand Down Expand Up @@ -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<void*> array(new void*[asize]);
const int count = backtrace(array, asize);
const char tool[] = "/usr/bin/addr2line";
char* prog = progpath();
Expand Down
9 changes: 4 additions & 5 deletions src/mstring.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/wmdock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ void DockApp::proper() {
if (intern) {
const int count = docks.getCount();
if (count) {
Atom atoms[count];
asmart<Atom> atoms(new Atom[count]);
for (int i = 0; i < count; ++i) {
atoms[i] = Atom(docks[i].client->handle());
}
Expand Down
2 changes: 1 addition & 1 deletion src/wmmgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,7 @@ void YWindowManager::setDesktopCount() {
void YWindowManager::setDesktopViewport() {
MSG(("setting: _NET_DESKTOP_VIEWPORT"));
const int n = 2 * workspaceCount;
Atom data[n];
asmart<Atom> data(new Atom[n]);
for (int i = 0; i < n; ++i)
data[i] = 0;
setProperty(_XA_NET_DESKTOP_VIEWPORT, XA_CARDINAL, data, n);
Expand Down
2 changes: 1 addition & 1 deletion src/wmpref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> index(new int[count]);
for (int i = 0; i < count; ++i) {
index[i] = i;
}
Expand Down
1 change: 1 addition & 0 deletions src/wmswitch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/yarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "config.h"
#include "mstring.h"
#include "yarray.h"
#include "ypointer.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
Expand Down Expand Up @@ -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<unsigned char> copy(new unsigned char[fElementSize]);
memcpy(copy, getElement(index), fElementSize);
if (index < place) {
memmove(getElement(index), getElement(index + 1),
Expand Down
5 changes: 3 additions & 2 deletions src/yfontxft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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<wchar_t> copy(new wchar_t[size]);

memcpy(copy, str, lo * sizeof(wchar_t));
copy[lo] = el;
copy[lo + 1] = 0;
Expand Down Expand Up @@ -320,7 +321,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<wchar_t> copy(new wchar_t[size]);
memcpy(copy + 1, str + len - lo, lo * sizeof(wchar_t));
copy[0] = el;
copy[lo + 1] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/yscrollview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/yxtray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Window> windows(new Window[count]);

for (IterType ec = fDocked.iterator(); ++ec; )
windows[ec.where()] = ec->leader();
Expand Down

0 comments on commit d6bedaa

Please sign in to comment.