-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
update memory allocate check #30
base: master
Are you sure you want to change the base?
Conversation
cmockery is dead since several years, you probably want to take a look at https://cmocka.org which is the successor of cmockery. We are happy to accept patches to improve it. |
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.
Sorry about the slow response on this.
@@ -1377,6 +1379,22 @@ void* _test_calloc(const size_t number_of_elements, const size_t size, | |||
return ptr; | |||
} | |||
|
|||
//Chech if the address is really allocated |
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.
Chech --> Check
const ListNode * const head = get_allocated_blocks_list(); | ||
const ListNode *node = head->next; | ||
int rc = 0; | ||
while(node != head){ |
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.
We roughly follow google C++ style https://google.github.io/styleguide/cppguide.html in here.
So this should have some whitespace...
"while (node != head) {"
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.
Same sort of this below with the "if" statements
@@ -21,7 +21,7 @@ | |||
#endif | |||
#include <sys/types.h> | |||
|
|||
#if UNIT_TESTING | |||
//#if UNIT_TESTING |
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.
We need to keep this in place so that the wrapper for the allocator is only in place when testing.
If we pass an invalid pointer to _test_free() function, this function will be crashed. So I update this function, add some checking code. Therefore, cmockery can test cases that free invaild pointer, and free an allocated block twice.