Skip to content

Commit

Permalink
Merge pull request #3281 from BsAtHome/fix_clang-vla-problems
Browse files Browse the repository at this point in the history
Fix clang vla problems
  • Loading branch information
andypugh authored Jan 15, 2025
2 parents 6b242af + b8434f8 commit ba7542e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
20 changes: 10 additions & 10 deletions src/emc/rs274ngc/interp_convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3652,17 +3652,17 @@ int Interp::restore_settings(setup_pointer settings,
if (!cmd.empty()) {
// the sequence can be multiline, separated by nl
// so split and execute each line
char buf[cmd.size() + 1];
strncpy(buf, cmd.c_str(), sizeof(buf));
char *last = buf;
char *s;
while ((s = strtok_r(last, "\n", &last)) != NULL) {
std::string cpy = cmd;
char *stateptr = NULL;
char *s = strtok_r(cpy.data(), "\n", &stateptr);
while (s != NULL) {
int status = execute(s);
if (status != INTERP_OK) {
char currentError[LINELEN+1];
rtapi_strxcpy(currentError,getSavedError());
CHKS(status, _("M7x: restore_settings failed executing: '%s': %s"), s, currentError);
}
s = strtok_r(NULL, "\n", &stateptr);
}
write_g_codes((block_pointer) NULL, settings);
write_m_codes((block_pointer) NULL, settings);
Expand Down Expand Up @@ -3721,18 +3721,18 @@ int Interp::restore_from_tag(StateTag const &tag)
if (!cmd.empty()) {
// the sequence can be multiline, separated by nl
// so split and execute each line
char buf[cmd.size() + 1];
strncpy(buf, cmd.c_str(), sizeof(buf));
char *last = buf;
char *s;
while ((s = strtok_r(last, "\n", &last)) != NULL) {
std::string cpy = cmd;
char *stateptr = NULL;
char *s = strtok_r(cpy.data(), "\n", &stateptr);
while (s != NULL) {
int status = execute(s);
if (status != INTERP_OK) {
char currentError[LINELEN+1];
strcpy(currentError,getSavedError());
CHKS(status, _("Failed to restore interp state on abort "
"'%s': %s"), s, currentError);
}
s = strtok_r(NULL, "\n", &stateptr);
}
write_g_codes((block_pointer) NULL, &_setup);
write_m_codes((block_pointer) NULL, &_setup);
Expand Down
11 changes: 7 additions & 4 deletions src/hal/halmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <structmember.h>
#include <string>
#include <map>
#include <vector>
using namespace std;

#include "config.h"
Expand Down Expand Up @@ -1742,8 +1743,10 @@ static int pystream_init(PyObject *_self, PyObject *args, PyObject *kw) {
PyObject *stream_read(PyObject *_self, PyObject *unused) {
streamobj *self = (streamobj *)_self;
int n = PyBytes_Size(self->pyelt);
hal_stream_data buf[n];
if(hal_stream_read(&self->stream, buf, &self->sampleno) < 0)
if(n <= 0)
Py_RETURN_NONE;
vector<hal_stream_data> buf(n);
if(hal_stream_read(&self->stream, buf.data(), &self->sampleno) < 0)
Py_RETURN_NONE;

PyObject *r = PyTuple_New(n);
Expand Down Expand Up @@ -1783,7 +1786,7 @@ PyObject *stream_write(PyObject *_self, PyObject *args) {
return NULL;
}

hal_stream_data buf[n];
vector<hal_stream_data> buf(n);
for(int i=0; i<n; i++) {
PyObject *o = PyTuple_GET_ITEM(data, i);
switch(PyBytes_AS_STRING(self->pyelt)[i]) {
Expand All @@ -1794,7 +1797,7 @@ PyObject *stream_write(PyObject *_self, PyObject *args) {
default: memset(&buf[i], 0, sizeof(buf[i])); break;
}
}
int r = hal_stream_write(&self->stream, buf);
int r = hal_stream_write(&self->stream, buf.data());
if(r < 0) {
errno = -r; PyErr_SetFromErrno(PyExc_IOError); return 0;
}
Expand Down
11 changes: 9 additions & 2 deletions src/hal/utils/halcmd_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include <errno.h>
#include <time.h>
#include <fnmatch.h>

#include <vector>

static int unloadrt_comp(char *mod_name);
static void print_comp_info(char **patterns);
Expand Down Expand Up @@ -2599,7 +2599,14 @@ static void save_comps(FILE *dst)
next = comp->next_ptr;
}

hal_comp_t *comps[ncomps], **compptr = comps;
if(!ncomps) {
// No components found, bail
rtapi_mutex_give(&(hal_data->mutex));
return;
}

std::vector<hal_comp_t *> comps(ncomps, nullptr);
hal_comp_t **compptr = comps.data();
next = hal_data->comp_list_ptr;
while(next != 0) {
comp = SHMPTR(next);
Expand Down
13 changes: 10 additions & 3 deletions src/rtapi/uspace_rtapi_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,21 @@ static int read_number(int fd) {

static string read_string(int fd) {
int len = read_number(fd);
char buf[len];
if(read(fd, buf, len) != len) throw ReadError();
return string(buf, len);
if(len < 0)
throw ReadError();
if(!len)
return string();
string str(len, 0);
if(read(fd, str.data(), len) != len)
throw ReadError();
return str;
}

static vector<string> read_strings(int fd) {
vector<string> result;
int count = read_number(fd);
if(count < 0)
return result;
for(int i=0; i<count; i++) {
result.push_back(read_string(fd));
}
Expand Down

0 comments on commit ba7542e

Please sign in to comment.