-
Notifications
You must be signed in to change notification settings - Fork 18
Fix #678: Fix stats print on ARM due to indeterminate state of "va_list" parameter after vasprintf #933
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 #678: Fix stats print on ARM due to indeterminate state of "va_list" parameter after vasprintf #933
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,10 +194,24 @@ double boxMuller(float m, float s) { | |
|
|
||
| double randf() { return (double)random() / RAND_MAX; } | ||
|
|
||
| char *vstrcatf(char **dest, const char *fmt, va_list ap) { | ||
| char *vstrcatf(char **dest, const char *fmt, va_list &ap) { | ||
| char *tmp; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add null pointer checks for |
||
| int n = *dest ? strlen(*dest) : 0; | ||
| int i = vasprintf(&tmp, fmt, ap); | ||
|
|
||
| va_list va_copy; | ||
| va_copy(va_copy, ap); | ||
| int i = vasprintf(&tmp, fmt, va_copy); | ||
| va_end(va_copy); | ||
|
|
||
| // Advance va_list | ||
| const char *format = fmt; | ||
| if (strcmp(format, "%ju") == 0) { | ||
| va_arg(ap, unsigned int); | ||
| } else if (strcmp(format, "%lf") == 0) { | ||
| va_arg(ap, double); | ||
| } else if (strcmp(format, "%s") == 0) { | ||
| va_arg(ap, char *); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is real-time critical code. But you could avoid one allocation by doing: size_t n = vsnprintf(NULL, 0, fmt, va_copy);
*dest = (char *)(realloc(*dest, n + i + 1));
vsnprintf(*dest + n, n+1, fmt, va_copy);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering, isnt it also UB to call @IgnoreWarnings wrote in #678
|
||
|
|
||
| *dest = (char *)(realloc(*dest, n + i + 1)); | ||
| if (*dest != nullptr) | ||
|
|
@@ -228,7 +242,7 @@ char *strf(const char *fmt, ...) { | |
| return buf; | ||
| } | ||
|
|
||
| char *vstrf(const char *fmt, va_list va) { | ||
| char *vstrf(const char *fmt, va_list &va) { | ||
| char *buf = nullptr; | ||
|
|
||
| vstrcatf(&buf, fmt, va); | ||
|
|
||
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'm surprised you don't need
const char* restrict fmt.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.
To my knowledge
restrictis a C not C++ keyword?Are you concerned about aliasing between the
*destandfmtpointers?I dont fully understand, why we might need it..