-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add PWR079: Avoid undefined behavior due to uninitialized variables #56
Conversation
c867f22
to
5da5275
Compare
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.
LGTM
Checks/PWR079/README.md
Outdated
double sum = sum_array(array, 5); | ||
printf("Sum is: %f\n", sum); |
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.
Maybe avoid using sum
here to remove ambiguity with the sum
of the sum_array
function (same in the Fortran example).
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.
Agreed.
double sum = sum_array(array, 5); | |
printf("Sum is: %f\n", sum); | |
printf("Sum is: %f\n", sum_array(array, 5)); |
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 remove ambiguity
Good catch! Done in both the C and Fortran code examples.
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.
Looks great! Good job
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.
Looks good!
Checks/PWR079/README.md
Outdated
// example_array.c | ||
#include <stdio.h> | ||
|
||
__attribute__((pure)) double sum_array(double *array, int size) { |
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.
Nit:
__attribute__((pure)) double sum_array(double *array, int size) { | |
__attribute__((pure)) double sum_array(double *array, size_t size) { |
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 usually opt for int
to prevent including a header, but since stdio.h
is already used within this code example, fine by me! :)
Checks/PWR079/README.md
Outdated
double sum = sum_array(array, 5); | ||
printf("Sum is: %f\n", sum); |
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.
Agreed.
double sum = sum_array(array, 5); | |
printf("Sum is: %f\n", sum); | |
printf("Sum is: %f\n", sum_array(array, 5)); |
5da5275
to
0064465
Compare
0064465
to
f044084
Compare
Add entry and benchmark for a new check. My results:
This new check would also resolve #39. Nullifying pointers upon creation is suggested as part of the check.