Skip to content
  • Deucе's avatar
    3f7bf074
    Define and use a new IGNORE_RESULT() macro · 3f7bf074
    Deucе authored
    Historically, casting to void would suppress warnings about things
    being unused.  However, an attribute was created for functions like
    realloc() where not using the result is always a bug, so when the
    attribute is used, you must actually use the return value and can't
    cast to void to avoid a warning.
    
    Given this attribute, the glibc authors decided to apply it to all
    the functions that usually should have their return value checked
    (chdir(), write(), etc) when _FORTIFY_SOURCE is defined because if
    you care about correctness enough to define _FORTIFY_SOURCE, you'll
    always do something useful with these return values.
    
    Extending the hilarity, some distros define _FORTIFY_SOURCE by
    default.
    
    The result is functions that occasionally can safely be called
    regardless of the return value will throw a warning if you don't
    "do something" with that return value.
    
    Of course, you can just turn off the warnings completely with a
    compiler flag, but then you lose the excellent warning about things
    like realloc() that always make sense and were the original reason
    for the option.
    3f7bf074
    Define and use a new IGNORE_RESULT() macro
    Deucе authored
    Historically, casting to void would suppress warnings about things
    being unused.  However, an attribute was created for functions like
    realloc() where not using the result is always a bug, so when the
    attribute is used, you must actually use the return value and can't
    cast to void to avoid a warning.
    
    Given this attribute, the glibc authors decided to apply it to all
    the functions that usually should have their return value checked
    (chdir(), write(), etc) when _FORTIFY_SOURCE is defined because if
    you care about correctness enough to define _FORTIFY_SOURCE, you'll
    always do something useful with these return values.
    
    Extending the hilarity, some distros define _FORTIFY_SOURCE by
    default.
    
    The result is functions that occasionally can safely be called
    regardless of the return value will throw a warning if you don't
    "do something" with that return value.
    
    Of course, you can just turn off the warnings completely with a
    compiler flag, but then you lose the excellent warning about things
    like realloc() that always make sense and were the original reason
    for the option.
Loading