This is for a library dealing with extendable strings.
One of the functions I am to write says the following,
void XstrFree(Xstr x)
frees the extendable string pointed to by x, which must have the following properties:
1. Must not be NULL
2. Must have been originally returned from a call on one of the "creating" functions (lists the 3 creating functions)
3. Must not have already been freed by passing it a call of XstrFree()
If any of those requirements are not met, that is an error and the result of the call on XtrFree() is undefined.
I know 1 and 3 can be dealt with in checking to see of malloc !== NULL, but I am a little confused with #2. I am thinking that #2 follows the following "math" 1 <=> 2 <=> 3. Would I be correct to assume that? I do not see how the free() could be returned form the creating functions, since those functions return a "new extendable string" for each.
And also I'm curious on how the line of "In any of those..." can be interpreted. Meaning, just let the program crash if those three conditions are not met?
Code:psdo if (1 || 2 || 3) free(myMallocString); else //let program crash and burn