[previous] MISRA-C:2004  Rule  20.5:  (Required) [next] The error indicator errno shall not be used.
errno is a facility of C, which in theory should be useful, but which in practice is poorly defined by the standard. A non zero value may or may not indicate that a problem has occurred; as a result it shall not be used. Even for those functions for which the behaviour of errno is well defined, it is preferable to check the values of inputs before calling the function rather than rely on using errno to trap errors.

Example Code:


#include <errno.h>
#include "misra.h"
#include "m2cmex.h"

extern S16 test_2005( void )
{
   S16 r = 0;

   if ( errno != 0 )        /*  MISRA violation  */
   {
      r = 1;
   }

   return r;
}



QAC messages that encompass this guideline:

5119 The error indicator errno shall not be used.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents