Skip to content

Commit

Permalink
Stop using VLAs, they are not fully legal in C++
Browse files Browse the repository at this point in the history
  • Loading branch information
Code7R committed Oct 5, 2024
1 parent d5d7cfb commit 9c77c3b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 9 deletions.
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
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
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 @@ -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<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 @@ -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<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
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 9c77c3b

Please sign in to comment.