-
February 8th, 2016, 01:34 PM
#16
Re: Help! free() invalid pointer error
When you don't post the whole code, you are assuming that you know where the bug is, and that precludes other people from observing all possibilities. Not posting your whole code makes the problem hard to debug by others, and your code frustrating to look at, and well sort of on you to figure out in the end.
ahoodin
To keep the plot moving, that's why.
-
February 8th, 2016, 04:08 PM
#17
Re: Help! free() invalid pointer error
Code:
*(message*+size) = '\0';
assuming this is actual code, then should be
Code:
*(*message + size) = '\0';
but as others have requested, please post actual code.
Last edited by 2kaud; February 8th, 2016 at 04:10 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 8th, 2016, 06:07 PM
#18
Re: Help! free() invalid pointer error
Actually, you don't really need the temp buffer nor explicity null terminate *message. Consider (not tried)
Code:
*message = (uint8_t*)calloc(size + 1, sizeof(uint8_t));
for (int bytes = 0, ret = 0; bytes < size; bytes += ret)
if ((ret = recv(socket, *message + bytes, size - bytes, MSG_NOSIGNAL)) < 0)
{
free(*message);
*message = NULL;
return -1;
}
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|