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

Bug in functions() and variables() routines #261

Open
rw-schumann opened this issue Mar 18, 2019 · 0 comments
Open

Bug in functions() and variables() routines #261

rw-schumann opened this issue Mar 18, 2019 · 0 comments

Comments

@rw-schumann
Copy link

There is the ability to change the number of allowed functions and variables, which is great.

However, I only discovered it after pulling my hair out for a day with crashing code.

Bottom line the functions and variables routine does NOT error check that the defined arrays are kept within bounds. So if the defined limit was 5 functions but I made a sixth or tenth call to rest.functions(...) it merrily writes over memory leading to random fails.

In my local version I made both of those functions return an int, so I could indicate that the call failed. Then added safety checks before assigning the new values into the arrays and if the arrays are already full I just return an error condition (-1). See code snippet below

Would be happy to add to the primary release of of interest.

Rob

template
int variable(const char *name, T *var, bool quotable) {
if (variables_index >= NUMBER_VARIABLES)
return(-1);
variables[variables_index] = new TypedVariable(var, quotable);
variable_names[variables_index] = name;
variables_index++;
return(0);
}

template
int variable(const char *name, T *var) {
return(variable(name, var, true));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant