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

Question 2.76c second test case not appropriate #65

Open
zx000097 opened this issue Dec 20, 2020 · 0 comments
Open

Question 2.76c second test case not appropriate #65

zx000097 opened this issue Dec 20, 2020 · 0 comments

Comments

@zx000097
Copy link

The second test case used SIZE_MAX * 2 to test the another_calloc function.
However, if I comment out the if statement that checks the overflow, the function would still run fine with the given argument. It is because the malloc function will return NULL if the provided argument is way too big. The argument SIZE_MAX * 2 on a 64-bit machine returns 18446744073709551614, which is SIZE_MAX - 1, hence malloc (SIZE_MAX *2) will return NULL even if the overflow did occur in this case.

I think it is better to test the function by using two smaller arguments, such as (2^40)+1 and 2^24, but still causing overflow.

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