Menu

#1 Check return codes everywhere

open-accepted
nobody
None
5
2007-03-13
2007-02-15
No

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

Discussion

  • Tomáš Dolejší

    Logged In: YES
    user_id=644201
    Originator: NO

    Yes. Good point.

     
  • Tomáš Dolejší

    • status: open --> open-later
     
  • Markus Elfring

    Markus Elfring - 2007-03-12

    Logged In: YES
    user_id=572001
    Originator: YES

    Would you like to detect every error situation as early as possible?

     
  • Tomáš Dolejší

    • status: open-later --> open-accepted
     
  • Tomáš Dolejší

    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

     
  • Markus Elfring

    Markus Elfring - 2007-03-14

    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?

     
  • Tomáš Dolejší

    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.

     
  • Markus Elfring

    Markus Elfring - 2007-03-15

    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?

     
  • Tomáš Dolejší

    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.

     
  • Markus Elfring

    Markus Elfring - 2007-03-19

    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);
    }
    }

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.