#This script is designed to run with Understand - CodeCheck use base qw(Understand::Codecheck); use strict; use Codecheck::Libraries::InfoSiftr qw(getFunctionParams); use constant ERR1 => 'Violation: function "%1" includes a variable number of arguments.'; use constant ERR2 => 'Violation: "%1" used, which is expressly prohibited.'; sub register_tr_text { my $check = shift; $check->add_tr_text(ERR1); $check->add_tr_text(ERR2); } sub name { '16.1 Functions shall not be defined with variable numbers of arguments.' } sub description { '16.1 (Required) Functions shall not be defined with variable numbers of arguments.' } sub detailed_description { <<'END_DESC' There are a lot of potential problems with this feature. Users shall not write additional functions that use a variable number of arguments. This precludes the use of use of stdarg.h, va_arg, va_start and va_end. END_DESC } sub test_language { my $language = shift; return $language eq 'C++'; } sub test_entity { 1 } sub test_global { 0 } sub define_options { } sub check { my $check = shift; my $file = shift; return unless $file->kind->check('file'); my $lexer = $file->lexer(0); foreach my $ref ($file->filerefs('define, declare', 'function', 0)) { my @params = getFunctionParams($ref, $lexer); if (grep { $_ eq '...' } @params) { $check->violation($ref->ent, $ref->file, $ref->line, $ref->column, ERR1, $ref->ent->longname); } } return; }