#This script is designed to run with Understand - CodeCheck #Robert Gempeler - 7/19/2010 use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Use of "errno" statement.'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "20.5 - The error indicator \"errno\" shall not be used";} sub description { return "20.5 (Required) The error indicator \"errno\" shall not be used.";} sub detailed_description { return <<"END_DESC" "errno" is a facility of C, which in theory should be useful, but which in practice is poorly defned 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 defned, it is preferable to check the values of inputs before calling the function rather than rely on using "errno" to trap errors (see Rule 16.10). END_DESC } sub test_language { my $language = shift; return $language =~ /C\+\+/; #Handles C and C++ } sub test_entity { return 1;} sub test_global { return 0;} sub define_options{} sub check { my $check = shift; my $file = shift; return unless $file->kind->check("file ~unknown ~unresolved"); my @refs = $file->filerefs("use","object, macro",0); foreach my $ref (@refs){ if ($ref->ent->name =~ /^errno$/){ $check->violation($ref->ent(),$file,$ref->line(),$ref->column(),ERR1); } } }