Check return codes everywhere
Brought to you by:
reunion
Some checks for return codes are missing.
Examples:
Would you like to add more error handling for return values from "malloc" like in the function "main" and from "fprintf" in the function "dispatchstorageslot"?
http://mlf.svn.sourceforge.net/viewvc/mlf/trunk/main.c?revision=2&view=markup
Logged In: YES
user_id=644201
Originator: NO
Yes. Good point.
Logged In: YES
user_id=572001
Originator: YES
Would you like to detect every error situation as early as possible?
Logged In: YES
user_id=644201
Originator: NO
Please, let me know if these changes are a satisfactory. I will prepare a release then.
http://mlf.svn.sourceforge.net/viewvc/mlf/trunk/main.c?r1=3&r2=4
Logged In: YES
user_id=572001
Originator: YES
No - Your replacement of "fprintf" by "fputs" is not a complete solution.
Why do you still want to use unchecked function calls?
Logged In: YES
user_id=644201
Originator: NO
There reason why I wish to use 'fputs' because I don't need formatting (optiomization). The reason why I do not check the return values of theirs is that I couldn't think of anything that could possily go wrong. You seem to have a better idea so don't hesitate to tell me what exactly you wish I did.
Logged In: YES
user_id=572001
Originator: YES
I agree that a format string bug was fixed besides the optimisation effect.
You do not need to make assumptions about error situations. Please check all return values. Otherwise, it might not be noticed if anything unexpected went wrong.
Can you imagine that a drive will become full or a network transmission will be damaged?
Logged In: YES
user_id=644201
Originator: NO
http://mlf.svn.sourceforge.net/viewvc/mlf/trunk/main.c?r1=4&r2=5
Please, let me know if you think this solution would actually catch an error such as you propose.
Logged In: YES
user_id=572001
Originator: YES
I would recommend the following wrapper function:
inline void stdputs(char const * const text)
{
if (fputs(text, stdout))
{
perror("Could not write to stdout.");
exit(errno);
}
}