-
Notifications
You must be signed in to change notification settings - Fork 8
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
Calling add #107
Comments
Remember that specifications are always defined/meaningful. int add(int x, int y)
/*@ requires (x >= 0i32 || y >= 0i32) implies x <= x + y && y <= x + y;
x < 0i32 && y < 0i32 implies x + y <= x && x + y <= y;
ensures return == x + y;
@*/
{
return x + y;
} You could always try to just copy secure coding standards into specs, but I think that would be ugly |
Isn't that spec wrong, e.g, when x is 1 and y is -3? The link has a proper check in the "Compliant Solution" subsection of "Addition". Consider providing an example spec based on that and mentioning the link in the tutorial to help others. |
Please submit a PR if it's urgent. |
In the original question, I was actually asking what to put in the if (...) of the function "another_func" which is calling add. Copying from the coding standards guide, the IF statement is still not sufficient though: Here's the self-contained code of a representative example of what we're trying to do.
|
As a follow-on to writing the spec for add_0.c, it would be nice to have a tutorial for how a function can call add(x, y). We've run into a similar issue, and I'm not sure how to write the code to fulfill add(x,y)'s require clause. It's like:
Thanks!
The text was updated successfully, but these errors were encountered: