In the buffer code, identify the problems if:
(a) You do not use a temporary variable to realloc buffer;
(b) You do not test the buffer before each function.
(c) You do not free the memory in case of error
a) There will be undefined behavior because there is memory violation and invalid memory access.
b) There might be a buffer overflow because the function can try to store more data in the buffer than the buffer can hold.
c) There can be leaking of resources or mutex leaking if the operating system does not clean up the memory.
Comments
Leave a comment