Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UndefinedBehaviourSanitizer errors. #1518

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/modlunit/units.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static int Getc(FILE* inp)
}

#define UNIT_STK_SIZE 20
static struct unit unit_stack[UNIT_STK_SIZE], *usp;
static struct unit unit_stack[UNIT_STK_SIZE], *usp{nullptr};

static char* neuronhome() {
#if defined(WIN32)
Expand Down Expand Up @@ -214,9 +214,13 @@ char *Unit_str(unit* up)
}

void unit_pop() {
IFUNITS
assert(usp >= unit_stack);
--usp;
IFUNITS
assert(usp >= unit_stack);
if (usp == unit_stack) {
usp = nullptr;
} else {
--usp;
}
}

void unit_swap() { /*exchange top two elements of stack*/
Expand Down Expand Up @@ -277,20 +281,23 @@ void ucopypush(unit* up)
usp->isnum = up->isnum;
}

void Unit_push(char* str)
{
IFUNITS
assert(usp < unit_stack + (UNIT_STK_SIZE - 1));
++usp;
pc = str;
if (str) {
usp->isnum = 0;
}else{
pc = "";
usp->isnum = 1;
}
convr(usp);
/*printf("unit_push %s\n", str); units(usp);*/
void Unit_push(char* str) {
IFUNITS
assert(usp < unit_stack + (UNIT_STK_SIZE - 1));
if (usp) {
++usp;
} else {
usp = unit_stack;
}
pc = str;
if (str) {
usp->isnum = 0;
} else {
pc = "";
usp->isnum = 1;
}
convr(usp);
/*printf("unit_push %s\n", str); units(usp);*/
}

void unit_push_num(double d)
Expand Down Expand Up @@ -565,10 +572,10 @@ fprintf(stderr, "The previous expression needs the conversion factor (%g)\n",
}

void unit_stk_clean() {
IFUNITS
usp = unit_stack - 1;
IFUNITS
usp = nullptr;
}

// allow the outside world to call either modl_units() or unit_init().
static void units_alloc() {
int i;
Expand Down
25 changes: 13 additions & 12 deletions src/nrniv/nonlinz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,20 +532,21 @@ void NonLinImpRep::dsds() {
}
}

void NonLinImpRep::current(int im, Memb_list* ml, int in) { // assume there is in fact a current method
Pvmi s = memb_func[im].current;
// fake a 1 element memb_list
Memb_list mfake;
void NonLinImpRep::current(int im, Memb_list* ml, int in) { // assume there is in fact a current
// method
Pvmi s = memb_func[im].current;
// fake a 1 element memb_list
Memb_list mfake;
#if CACHEVEC != 0
mfake.nodeindices = ml->nodeindices + in;
mfake.nodeindices = ml->nodeindices + in;
#endif
mfake.nodelist = ml->nodelist+in;
mfake.data = ml->data + in;
mfake.pdata = ml->pdata + in;
mfake.prop = ml->prop + in;
mfake.nodecount = 1;
mfake._thread = ml->_thread;
(*s)(nrn_threads, &mfake, im);
mfake.nodelist = ml->nodelist + in;
mfake.data = ml->data + in;
mfake.pdata = ml->pdata + in;
mfake.prop = ml->prop ? ml->prop + in : nullptr;
mfake.nodecount = 1;
mfake._thread = ml->_thread;
(*s)(nrn_threads, &mfake, im);
}

void NonLinImpRep::ode(int im, Memb_list* ml) { // assume there is in fact an ode method
Expand Down