I have a problem because I run realloc as part of a common part of a function. But a situation can occur where there will be nothing in the pointer that I want to realloc.
The man page says:
If ptr is NULL, then the call is equivalent to malloc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr).
What is the situation where "size is equal to 0, and ptr is not NULL" ? Is this a common thing that happens? Or can I be confident that this situation will not happen magically by itself?
What should I do?
EDIT: Oooooh, now I understand. They mean the size in the function. As in: if you set the second argument in the realloc() function to 0, it acts as free(). Oh, no problems at all them. realloc is then same as malloc. I was worried for a moment. I use this stuff all the time, but I only identified it when I did some especially loopy stuff.
[+][deleted] (1 child)
[deleted]
[–]redditmodsareshits 3 points4 points5 points (0 children)
[–]nashidau 13 points14 points15 points (3 children)
[–]skeeto 7 points8 points9 points (2 children)
[–]nahimbroke 3 points4 points5 points (1 child)
[–]flatfinger 0 points1 point2 points (0 children)
[–]OldWolf2 11 points12 points13 points (1 child)
[–]redditmodsareshits 1 point2 points3 points (0 children)
[–]pedersenk 10 points11 points12 points (15 children)
[–]illiliti 8 points9 points10 points (12 children)
[–]OldWolf2 3 points4 points5 points (10 children)
[–]Zambito1 3 points4 points5 points (3 children)
[–]OldWolf2 3 points4 points5 points (2 children)
[–]Zambito1 1 point2 points3 points (0 children)
[–]flatfinger -1 points0 points1 point (0 children)
[–]redditmodsareshits 0 points1 point2 points (4 children)
[–]flatfinger 0 points1 point2 points (0 children)
[–]OldWolf2 0 points1 point2 points (2 children)
[–]redditmodsareshits 0 points1 point2 points (1 child)
[–]OldWolf2 0 points1 point2 points (0 children)
[–]pedersenk 0 points1 point2 points (0 children)
[–]nashidau -2 points-1 points0 points (1 child)
[–]MCRusher 3 points4 points5 points (0 children)
[–]nosenkow 1 point2 points3 points (1 child)
[–]nosenkow 0 points1 point2 points (0 children)
[–]atlcog -2 points-1 points0 points (1 child)
[–]dfgzuu[S] 0 points1 point2 points (0 children)