-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
cleanup: Convert all variable length arrays to heap allocations #100
Conversation
d97782d
to
9b98852
Compare
961a962
to
9dafa15
Compare
198b851
to
bd4fc6a
Compare
src/toxic.c
Outdated
@@ -837,6 +888,7 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, Tox_Err_New | |||
|
|||
if (store_data(m, data_path) == -1) { | |||
exit_toxic_err("failed in load_tox", FATALERR_FILEOP); | |||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You added a lot of return NULL;
after exit_toxic_err
calls. Don't they exit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added those to see if they would get rid of a strange codefactor warning, which they did. So I can either leave them (harmless) or @iphydf can fix the false positive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to leave them in even though CodeFactor no longer is a required check?
88bff06
to
e7ae063
Compare
Two of the CodeFactor warnings are false positives ( All of the Codacity warnings about
A C string is null terminated by definition. The warning amounts to "if this is buggy code it might crash". |
e7ae063
to
a4468c9
Compare
a4468c9
to
351f38a
Compare
060f52c
to
69f088a
Compare
Three of the four codefactor issues have been fixed. To summarize:
Still don't know what to do about |
1d28c6f
to
2a4b4e3
Compare
53c0eaa
to
d6f0ca2
Compare
VLA's are inherently unsafe so the safest option is to not use them
Instead of using various different forms of string arrays and having to handle them differently for string completion, we now always use char pointer arrays. This allows us to remove some large stack allocations, remove a bunch of confusing defines that keep track of global array sizes, and generally unclutters the code so it's easier to read.
d6f0ca2
to
2d10677
Compare
src/toxic.c
Outdated
@@ -837,6 +888,7 @@ static Tox *load_tox(char *data_path, struct Tox_Options *tox_opts, Tox_Err_New | |||
|
|||
if (store_data(m, data_path) == -1) { | |||
exit_toxic_err("failed in load_tox", FATALERR_FILEOP); | |||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going to leave them in even though CodeFactor no longer is a required check?
Also moved some single use functions from misc_tools to their respective files
2d10677
to
e7a0c32
Compare
VLA's are inherently unsafe so the safest option is to not use them. The trade off here is a lot of extra code for mallocs/frees and more possible memory leaks. But I think that's a small price to pay for greatly reducing the possibility of stack corruption.
I also added the -Wvla compile option to the Makefile, which gives a warning when VLA's are used.
This change is