#This script is designed to run with Understand - CodeCheck #Robert Gempeler - 7/19/2010 use base ("Understand::Codecheck"); use strict; use constant ERR1 => 'Violation: File contains invalid dynamic memory statement.'; sub register_tr_text() { my $check = shift; $check->add_tr_text(ERR1); } sub name { return "20.4 Dynamic heap memory allocation shall not be used";} sub description { return "20.4 (Required) Dynamic heap memory allocation shall not be used";} sub detailed_description { return <<"END_DESC" This precludes the use of the functions calloc, malloc, realloc and free. There is a whole range of unspecifed, undefned and implementation-defned behaviour associated with dynamic memory allocation, as well as a number of other potential pitfalls. Dynamic heap memory allocation may lead to memory leaks, data inconsistency, memory exhaustion, non- deterministic behaviour. 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"); my @functionCallRefs = $file->filerefs("call","function",0); foreach my $funcCall (@functionCallRefs){ if ($funcCall->ent->name =~ /^calloc$|^malloc$|^realloc$|^free$/){ $check->violation($funcCall->ent(),$file,$funcCall->line(),$funcCall->column(),ERR1); } } }