0% found this document useful (0 votes)
9 views24 pages

Nokia Code Quality Rules Guide

The document outlines a comprehensive set of coding rules for developers, emphasizing best practices such as naming conventions, variable initialization, and code structure. It provides guidelines for using preprocessor macros, managing function arguments, and ensuring code readability. Additionally, it details how to run a code checker tool to enforce these rules and check for violations in source files.

Uploaded by

rakshit maggon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views24 pages

Nokia Code Quality Rules Guide

The document outlines a comprehensive set of coding rules for developers, emphasizing best practices such as naming conventions, variable initialization, and code structure. It provides guidelines for using preprocessor macros, managing function arguments, and ensuring code readability. Additionally, it details how to run a code checker tool to enforce these rules and check for violations in source files.

Uploaded by

rakshit maggon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

USER AND DEVELOPER GUIDE

USER GUIDE

EXISTING RULES:
SL NO. RULE RULE DESCRIPTION
NUMBER

1 RULE 1 Switch should always have a default case.

2 RULE 2 The names of preprocessor macros shall be entirely uppercase with w


ords separated by underscore.

3 RULE 3 Only permit to use ASCII characters in our code files.

4 RULE 4 Don’t use tab instead prefer 4 spaces

5 RULE 5 Number of characters per line should not exceed more than 80

6 RULE 6 We need to avoid to use


global variables. If we should use it indeed, we need to add a prefix g
_ to easily distinguish it from local variables.

7 RULE 7 Always initialize local variables .

8 RULE 8 Long function bodies


must be avoided. Recommended size is not more than 60 statements

9 RULE 9 All of a project's header files should be listed/included as descendants


of the project's source directory without use of UNIX directory shortc
uts

10 RULE 10 When pre-processor macros


are used, all appearances of each macro argument must be enclosed in
parenthesis.

11 RULE 11 Function argument should not be returned.

12 RULE 12 Enum names shall be entirely uppercase with words separated by und
erscore.

13 RULE 13 Data members of structs are named like ordinary nonmember variable
s. They do not have the trailing underscores that data members in
classes have.

14 RULE 14 Local/Stack variables should not be returned.

15 RULE 15 In a switch statement, each case must end with a break or a return
statement.

Nokia internal use


16 RULE 16 All header files should have #define guards to prevent multiple inclusion.

17 RULE 17 Upon creation, all pointers must be initialized either to 0 (NULL) or


to an object.

18 RULE 18 Filenames should be all lowercase and include underscores(_)

19 RULE 19 Functions with many arguments must be avoided. They often indicate
improper design.

20 RULE 20 Inline functions should only be used for sufficiently simple functions.

21 RULE 21 The name of the files shall only contain one period, to separate the
file extension.

22 RULE 22 Header files shall have the extension .h for both C and C++ files

23 RULE 23 The names of formal arguments to functions must


always be specified and must be the same both in the
function declaration and in the function definition.
24 RULE 24 The return value of a function should generally not be void

25 RULE 25 Function names should (in general) not


contain "and".
26 RULE 26 Functions shall not contain too many nesting levels (nested if-else-for-
while-...) statements).

27 RULE 27 When defining a function, parameter order is: inputs, then outputs.

28 RULE 28 Brackets should occupy a new line in the source code.

29 RULE 29 Pointers to pointer as function argument must be avoided whenever


possible.

30 RULE 30 Variables in conditional statements shall not form unary conditional


expressions, unless the variables are boolean type.

Nokia internal use


31 RULE 31 The const keyword should be used where possible. For predefined
strings, use const char * rather than char *.
32 RULE 32 The names of variables and data members are all lowercase, with
underscores between words.
33 RULE 33 A function shall not return a pointer or reference to its automatic
(stack) variables.
34 RULE 34 The type of function pointers must be typedef-ed.
35 RULE 35 Functions with boolean return values and no output parameters
should be named with prefixes is, are, has, exist.
36 RULE 36 Every code block should use brackets. Disallow to omit brackets.

37 RULE 37 Functions used in conditional statements shall not form unary


conditional expression, unless their return value is of boolean type.

How to run the rules?

 To run all the rules together using a single script, trigger [Link] inside
code_checker_tool directory with git or hg repo as its argument in command line.

>python [Link] <hg or git repo’s root directory>

Here <hg or git repo’s root directory> is a git or hg repo where we are trying to check
for the violations in files(.c files and .h files).

 To run specific rules, we can edit the rules we want to run in


code_checker_tool/[Link] and then trigger [Link] as specified above.

 This will collect the list of files modified from all outgoing changesets and run with
all the implemented rules.

 This script will generate logs directory with master log and log with respective source
file name.

 Can check [Link] for more information on execution of code checker tool.

How to check the logs?

 Logs will be generated for violation in every rule.

Nokia internal use


 Individual logs will be generated for each file which are checked if there is any error
in it. The logs will be generated with the name of the file we are checking for the rules.
Example: If we have a rule violation in a source file named call.c then [Link] will
be created in Logs folder if there are any violations in any of the rules.
 Master log will contain the violations in all the modified files.
Path: /code_checker_tool/Logs

[Link]:

Examples for violations

RULE 1 à Switch should always have a default case.

àTool : Pycparser

#include <stdio.h> Violation cases:

int main() · no default case

int x = 2;

switch (x)

case 1: printf("Choice is 1");

case 2: printf("Choice is 2");

Nokia internal use


break;

case 3: printf("Choice is 3");

break;

return 0;

Violation cases:

#include <stdio.h> · NONE

int main() {

int num = 8;

switch (num) {

case 7:

printf("Value is 7");

break;

case 8:

printf("Value is 8");

break;

case 9:

return 9;

default:

printf("Out of range");

break;

return 0;

RULE 2 à The names of the preprocessor macros shall be entirely uppercase with two words
separated by underscore.

àTool: python and regex

Nokia internal use


#ifndef fILE_FOO_SEEN Violation case : name of preprocessor macro
#define fILE_FOO_SEEN should be entirely upper case (f is in small letter
in macro fILE_FOO_SEEN)
the entire code

#endif /* fILE_FOO_SEEN */

RULE 3 à Only permit to use ASCII characters in our code files.

àTool : Python

#include <stdio.h> Violation case: None


int main()
{
char ch; // variable declaration
printf("Enter a character");
scanf("%c",&ch); // user input
printf("\n The ascii value of the ch variable is :
%d", ch); //prints ascii value for the character
entered

return 0;
}
#include <inttypes.h> Violation case : “ – non ASCII character in printf
#include <stdio.h> statements

typedef enum{false, true} bool;

bool is_little_endian()
{
int x = 1;
char *y = (char*)&x;
return 1;
}

unsigned int merge_bytes( unsigned int x,


unsigned int y )
{
return (y & 0xffffff00) | (x & 0xff);
}

unsigned int replace_byte (unsigned int x, int i,


unsigned char b)
{

int shift = (b << (8 * i));


int mask = 0xff << shift;
return (~mask & x) | shift;
}

int main()

Nokia internal use


{
if( is_little_endian() )
{
printf(“Your machine is a Little Endian machine\
n”);
}

int x = 0x89ABCDEF;
int y = 0x76543210;
printf(“Merged number = 0x%x\n”,
merge_bytes(x,y));
return 0;
}

RULE 4 à Don’t use tab instead prefer 4 spaces

à Tool: Python

#include<stdio.h> Violation case:


Int main() Use of tab before int a=10;
{
int a=10;
printf(“don’t use tab ”);
}

RULE 5 à Number of characters per line should not exceed more than 80

àTool : Python

à a statement with more than 80 characters (including comments) – violation case

RULE 6 à We need to avoid to use global variables. If we should use it indeed, we need to add

a prefix g_ to easily distinguish it from local variables.

à Tool: Pycparser

#include<conio.h> Violation case: global variables (a, b)does not


int a=10,b; //global variables have prefix g_ (to distinguish it from local
void main() variables)
{
int x=23,y=4; // local variables
printf(“a = %d and b=%d”,a,b);
}

RULE 7 à Always initialize local variables .

àTool : Pycparser

#include<conio.h> Violation case: initialize local variables x and y.


int g_a=10,g_b; //global variables

Nokia internal use


void main()
{
int x,y; // local variables
printf(“a = %d and b=%d”,a,b);
}

RULE 8 à Long function bodies must be avoided. Recommended size is not more than 60 statements

à Tool: Pycparser

à Violation case : function body that has more than 60 statements.(excluding comments)

RULE 9 à
All of a project's header files should be listed/included as descendants of the project's source directo
ry without use of UNIX directory shortcuts

àTool : Python

#include <stdio.h> Violation case: header files should be listed/


#include "./../././Boo.h" included as descendants of project’s source
directory without use of UNIX directory
int qwer; shortcuts.
int ab = 1000;
int g_test = 5000;
int main(){
int local_variable = 50;
switch(myvar)
{
case 10:
k = 10;
p = k + 1;
return 10;
case 20:
case 30:
return 20;
default:
break;
}

switch(myvar)
{
case 101:
k = 10;
p = k + 1;
return 10;
case 120:
case 130:
return 20;
}
return 0;
}

Nokia internal use


int add(qwer, ab){

int dummy;
int dummy2;
return 0;
}

RULE 10 à When pre-processor macros


are used, all appearances of each macro argument must be enclosed in parenthesis.

àTool: Python

#define DOUBLE(x) ( x * 2 ) // Violation case: x – macro argument is not


BAD enclosed with paranthesis

#define DOUBLE(x) ( (x) * 2 ) // Violation case: none


OK

RULE 11 à Function argument should not be returned.

àTool : Pycparser

#include <stdio.h> Violation case : returns function argument


int my_function(int x) {
printf("This will take an argument, and will
return its squared value\n");
return x;
}
int main() {
int x, res;
x = 12;
res = my_function(12);
printf("Returned Value: %d", res);
return 0;
}

RULE 12 à Enum names shall be entirely uppercase with words separated by underscore.

àTool: Pycparser

enum week{Mon, Tue, Wed, Thur, Fri, Sat, violation case : enum names should be entirely
Sun}; uppercase with words separated by underscore

int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}

Nokia internal use


RULE 13 à
Data members of structs are named like ordinary nonmember variables. They do not have the trailin
g underscores that data members in classes have.

àTool : Pycparser

struct UrlTableProperties { Violation case: in structures, int num_entries_


string name; has trailing underscores
int num_entries_;
static Pool<UrlTableProperties>* pool;
};
Int main(){
string table_name_; // OK - underscore at end.
static Pool_; // OK.
}

RULE 14 à Local/Stack variables should not be returned.

àTool: Pycparser

char* getName() { Violation case: returns a stack variable


char name[STR_MAX];
fillInName(name);
return name;
}

RULE 15. In a switch statement, each case must end with a break or a return statement.
Tool: pycparser
With the help of ast tree , for each case statement we can check if it have break or return
statement and raise an error in other cases.
#include <stdio.h> Violation cases:
int main() · Case 1, no break or return
{
int x = 2;
switch (x)
{
case 1: printf("Choice is 1");
case 2: printf("Choice is 2");
break;
case 3: printf("Choice is 3");
break;
default: printf("Choice other than 1, 2
and 3");
break;
}
return 0;
Violation cases:
#include <stdio.h> · NONE
int main() {
int num = 8;

Nokia internal use


switch (num) {
case 7:
printf("Value is 7");
break;
case 8:
printf("Value is 8");
break;
case 9:
return 9;
default:
printf("Out of range");
break;
}
return 0;
}

Limitation:
This code only checks for switch cases in level 1.

RULE 16 à All header files should have #define guards to prevent multiple inclusion.
à Tool: python script
à The format of the symbol name should be <MODULE>_[EXPORT]|[INCLUDE]_<FILE>_H.
This rule is to guarantee guard's uniqueness. Example : Foo/export/baz.h should have the following
guard
#ifndef FOO_EXPORT_BAZ_H
1. define FOO_EXPORT_BAZ_H

2. endif //FOO_EXPORT_BAZ_H
/*gfb Violation case: int a is not gaurded
#define
#ifndef
#endif
* jsc
hch*/
int a; // int a is not guarded
#ifndef hhh_h
#define hhh_h

#endif

#ifndef HHHH_H Violation case: no endif


#define HHHH_H
/*nshdgj
* jahd*/
int getsr()
{
/*jhvd
dgfue*/
return 6;
}

Nokia internal use


#ifndef HHH_H // no define guards Violation case: no #define
int getrectanngle()
{
return 7
}
#endif

#ifndef SQUARE_H No violation


#define SQUARE_H
int getSquareSides()
{
return 4;
}
#endif

RULE 17. Upon creation, all pointers must be initialized either to 0 (NULL) or to an object.
Tool:pycparser
Check if the declaration is pointer and if it’s initialized either to 0 (NULL) or to an object.
If it’s not assigned to anything store it’s name and check if it’s assigned anywhere further in the
same block.
int main(){ Violation case:
int s=50; ‘check’ pointer is not initialized.
int *check;
int *check2=NULL;

printf("Value of check variable


is %d \n",*check);
printf("Value of check2 variable
is %d \n",check2);

return 0;
}

int main() Violation case:


{ ‘p’ pointer is not initialized.
int* pc; ‘fun_ptr’ pointer is not initialized.
double balance[5] = {1000.0,
2.0, 3.4, 17.0, 50.0};
double *d=balance;
char d='a';
int c = 5;
void (*fun_ptr)(int);//=&fun;
pc=&c;
int *p;
int (*fp) (int, int)=NULL;

printf("%d\n", *pc);

Nokia internal use


printf("%d", p);
return 0;
}

Limitation:
This code only checks for pointers in level 1 and won’t check for pointers in structures.

RULE 18 à Filenames should be all lowercase and include underscores(_)


e.g.,my_useful_class.c
à Tool : python and regular expression.
Filenamesà
Exam_ple.c Violation case //E
exam@.c Violation case//@
abcd_Gv.h Violation case//G
example.c No violation
exa_mple.c No violation

RULE 19. Functions with many arguments must be avoided. They often indicate improper design.
Tool:pycparser
Get the length of parameter’s list with the help of pycparser’s ast tree ,raise violation if length
exceeds the limit .
void averageAndRew(int aa, int Let’s say max count =3
b, int c, int d, int e); Violation case:
‘averageAndRew’ has [Link] arguments more
than maxcount.

RULE 20 à Inline functions should only be used for sufficiently simple functions.
à Tool : pycparser
à MAX_LINES=4
à Limitation case: more than 4 lines in inline functions
Violation case: 5 lines in inline function
inline void foo() i.e., more than 4 lines in inline function
{
int x;
printf("by");
//return 10 ; // returning the output value as
per requirement
}
static inline int food()
{
printf("hi");
int a;
printf(a);
int d=9;
return 20;

Nokia internal use


}
int main()
{
int x ;
// Calling the inline function
x = foo() ; // making a reference to inline
function.
printf( " The result of inline function is : %d\n "
,x);
return 0 ;
}

inline void foo() No violation


{
int x;
printf("by");
//return 10 ; // returning the output value as
per requirement
}

RULE 21. The name of the files shall only contain one period, to separate the file extension.
Tool: python
With the help of these commands we can get file name-
slash_index=file_input.rfind("/")
filename=file_input[slash_index+1:]
after getting filename we can check count of ‘.’ In file name to get [Link] extensions.
Filename: fun_c.c No violation
Filename: fun_c.c.c Violation case:
File name contain more than one period.

RULE 22 à Header files shall have the extension .h for both C and C++ files
à Tool: python script and regular expression
#include<[Link]> //violation Violation case: only .h is allowed
#include "square" //violation
int getsqr()
{
return 6;
}
int main()
{
return 3;
}
#include "geometry.h" // no violation No violation
int getsqr()
{
return 6;
}
int main()

Nokia internal use


{
return 3;
}

RULE 23. The names of formal arguments to functions must always be specified and must be the
same both in the function declaration and in the function definition.
Tool: pycparser
· Using pycparser get the variable names of function arguments at declaration and store
them in dictionary, and check if the names of function arguments are same in function
definition, if it’s not same violation occurs.
int addition(int *num1, int Violation case:
*num2); ‘addition’ function’s argument names are
int main(){} different in both declaration and definition.
int addition(int *a,int *b)
{
return *a + *b;
}

void averageAndRew(int aa, int Violation case:


b, int c, int d, int e); ‘averageAndRew’ function’s argument
void averageAndRew(int a, int b, names are different in both declaration and
int c, int d, int e) definition.
{
float avg;
avg = (a+b+c+d+e)/5;
printf("The average of given
five numbers : %f",avg); }

RULE 24 à The return value of a function should generally not be void :return an appropriate
value or error code so that the caller can handle success and failure appropriately.
à Tool: pycparser and python script
inline void foo(int *a) // violation Violation case
{
int x;
printf("by");
return 7;
}

static inline int food(int *b) //no violation No violation


{
//printf("hi");
//int a;
printf(a);
/*jasj
* jgcjs
* hjs*/
//sd
return 20;
}

Nokia internal use


int main() //no violation
{
int x ;
// Calling the inline function
x = foo() ; // making a reference to inline
function.
printf( " The result of inline function is : %d\n " ,
x);
return 0 ;
}

RULE [Link] names should (in general) not contain "And".


Tool:pycparser

· Using pycparser get the function name and check if the name have “And” in it , and
raise a violation if it exists.
void averageAndRew(int aa, int Violation case:
b, int c, int d, int e); ‘averageAndRew’ have And in
function name
Void bandName() No violation
{
}

RULE 26 à Functions shall not contain too many nesting levels (nested if-else-for-while-...)
statements). -- Having too many nesting levels indicates a refactoring is appropriate.
à Tool: pycparser.
à MAX_LIMIT_OF_LOOPS=4
à Limitation case -- More than 4 nesting levels is a violation
-- Does not support for loops(if-else-for-while-dowhile-switch) without
curly brackets { … }.
Sample code:
void TestForLoop() Violation case: the nesting level is more than 4
{ (max limit)
for(int x=0;x<2;x++) //1st
{
if(x==1)//2nd
{
for (int b = 0; b < 56; b++) //3rd
{
for (int c = 0; c < 196; c++) //4th
{
for(int d=0;d<200;d++) //violation because
more that 4 nesting levels #5th nesting level
{
printf("can vote");
}
}}}}}

int main(void) Limitation: pycparser does not support loops

Nokia internal use


{ without { … }
int i,j,factor;
printf("Finding perfect numbers: \n" );
for(i=1;i<10000;i++)
{
factor = 0;
for(j=1; j<i; j++)
{
if(i%j == 0) // exception case
//printf("hi");
for(int f=0;f<7;f++)
for(int q=0;q<10;q++)
printf("in for without {");

if(factor == i)
{
printf("%d", i);
printf("\n");
}
}}
}

RULE [Link] defining a function, parameter order is: inputs, then outputs.
Tool: pycparser
Using pycparser get the variable which is being returned by the function and check if it’s the
Last argument , if it’s not, raise a violation.
int subbb(x,z){ Violation case:
Function ‘subb’ parameters are not in
char a='b'; order as per rule.
return x;

Limitations: Works only for one output parameter


RULE 28 à Brackets should occupy a new line in the source code.
à all the curly braces(open ) should be in a new line.
à Tool: pycparser
à Limitation: pycparser doesn’t support for else condition and for closed curly braces.

int main() { // violation Violation case: the curly braces should be in a


… new line
}
If(){ //violation
While(true)
{ … //violation
}
}

Nokia internal use


int main() No violation: all the curly braces should be in a
{ // no violation new line

If()
{

}
}

RULE 29. Pointers to pointer as function argument must be avoided whenever possible.
Tool: pycparser
Using pycparser check if any of the function argument is a double/triple pointer and raise violation if
there a double pointer.

void swapAndChecking(int *a, int Violation case:


*b,int ***tem) ‘swapAndChecking’ have a
double/triple pointer argument
void swapAndChecking(int *a, int Violation case:
*b,int **tem) ‘swapAndChecking’ have a
double/triple pointer argument

RULE 30 à Variables in conditional statements shall not form unary conditional expressions, unless
the variables are boolean type.
à Tool: pycparser
à For example, the following statements are NOT allowed unless v is of boolean type:
if (v) ...
if (!v) ... if (v && ...) ...
int main () Violation case: the variables in conditional
{ statements (ex., if (…)) should be of Boolean
int i = 9; type // here d, i, x, t, c are of integer type.
for (int a = 0; a < 9; a++)
{
int d = 8;
if (d) //violation
{
printf ("everytime" "\n");
}
}

if (i) //violation
{
int x=3;
if (x) //violation
{
printf("if if""\n");
}

Nokia internal use


}
while (i < 7)
{
i--;
int t = 6;
if (t) //violation
{
printf ("ttt while" "\n");
}
}

int choice = 1;
int f;

switch (choice)
{
int c = 8;
case 1:
f = 6;
if (c) //violation
{
printf ("switch");
}
}
}

RULE [Link] const keyword should be used where possible. For predefined strings, use const char *
rather than char *.
Tool: pycparser
Python code using pycparser identifies every char pointer and checks if it’s predefined, after
validation it checks for const keyword and raise violation if it’s not there.
char *f='a'; Violation case:
‘f’ char pointer is not assigned with const
keyword.
Const char No violation
*string_id[5]={'a','b','c','d','
e'};

for( a = 10; a < 20; a = a + 1 ) Violation case:


{ ‘check’ char pointer is not assigned with const
char *check='a'; keyword.
printf("value of a:
%d\n", a);
}

RULE 32 à The names of variables and data members are all lowercase, with underscores between
words.
à Tool: python, pycparser and regular expression
variable names or data members

Nokia internal use


int Exam_ple; Violation case//E
int exam@; Violation case//@
int abcd_Gv; Violation case//G
int age; No violation
int exa_mple; No violation

RULE 33.A function shall not return a pointer or reference to its automatic (stack) variables.
Tool: pycparser
Pyhton code using pycparser make a list of variables, pointers which are declared inside function,
If the return statement consists of either a pointer or reference to its automatic (stack) variables
raise a violation .
int sumDigits() Violation case:
{ ‘&sum’ is reference to stack variable, so
int sum = 0; violation
int *a;
int digit;
if (sum==o)
{
int b=0;
}
for(digit = 0; digit <= 9; ++digit)
{
int *for1;
sum += digit;
}
return &sum ;
}

RULE 34 à The type of function pointers must be typedef-ed.


à Tool: pycparser
à Limitation case : pycparser does not support for function pointers inside structures.
#include<stdio.h> Violation case: because no typedef for function
void (*signal(int sig, void (*func)(int)))(int); pointer
//violation because no typedef for function
pointer

int subtraction (int a, int b) {


return a-b;
}

int main() { Violation case: because no typedef for function


int (*fp) (int, int)=subtraction; pointer
//Calling function using function pointer
void (*signal(int sig, void (*func)(int)))(int);
//violation because no typedef for function
pointer

int result = fp(5, 4);


printf(" Using function pointer we get the

Nokia internal use


result: %d",result);
return 0;
}

RULE [Link] with boolean return values and no output parameters should be named with
prefixes is, are, has, exist.
Tool: Pycparser
Python code using pycparser identifies if the function type is Boolean , then checks if the function
name starts with is, are, has, exist.
bool isPrime() No violation
{…
}
bool not_prime() Violation case:
{ ‘not_prime’ is a Boolean function with no is,
} are, has, exist prefix.

RULE 36 à Every code block should use brackets. Disallow to omit brackets.
à Tool : pycparser.
à All the blocks of the code (loops, functions, structures) should use { }.
à Limitation case: does not support loops inside any other loop without { … } ( i.e., for(…)
…if(…) )
int main () Violation case: some blocks of the code doesn’t
{ have brackets {…}
int i = 9;
for (int a = 0; a < 9; a++)
{
int d = 8;
if (d) //violation because of no { }

printf ("everytime" "\n");

if (i)
{
int x=3;
if (x) //violation because of no { }

printf("if if""\n");

}
while (i < 7)
{
i--;
int t = 6;
if (t) //violation because of no { }

Nokia internal use


printf ("ttt while" "\n");

int choice = 1;
int f;

switch (choice)
{
int c = 8;
case 1:
f = 6;
if (c)
{ //no violation
printf ("switch");
}
}
}

RULE 37 à functions used in conditional statements shall not form unary conditional expression,
unless their return value is of boolean type.
à Tool: pycparser
struct person Violation case: functions used in conditional
{ statements shall not form unary conditional
int x; expression,
int fp(); unless their return value is of boolean type.
int (*f) (int, int);

};
void (*signal(int sig, void (*func)(int)))(int);

int areSignalsPresent(){
int a=9;
int c=a*a;
return c;
}
int *main()
{
int i = 9;
for (int a1 = 0; a1 < 9; a1++)
{
int dQ = 8;
if (*f()) //violation
{
printf ("everytime" "\n");
}
}

Nokia internal use


if (i<3)
{
int x=3;
if (i)

printf("if if""\n");

}
while (i < 7)
{
i--;
int t = 6;
if (*signal()) //violation
{
int l=99;
printf ("ttt while" "\n");
}
}

int choice = 1;
int f;

if (*signal())
{
printf("c is 81");
}
return 0;
}

Developer Guide

How a new rule can be added?


 To add a new rule, write down the rule in /pycparser/code_checker_tool/ and test it
separately taking different files from c_files directory in the same folder.
 Rule number should be saved like this Rule<number>.py.
 All the rule violation source files will be in this format rule_<number>_violation.c
 In new rule<number>.py the implementation can be done using pycparser ast or
regex.
 After implementation and testing with all possible scenarios, now you’re good to go
for integration.

How to integrate implemented rules?

Nokia internal use


 In rule<number>.py, add the below line so that we can take the source file as an
argument.
file_path = [Link][1]
 Rule name should be added in [Link] present in the same folder.
(/pycparser/code_checker_tool/)
 Trigger test_run.py and ensure the new rule is getting invoked.

How to add new logs?


 In all the rules, currently we’re logging the rule that got violated along with file name
and line number.
 Refer existing [Link] and invoke below functions if required.
o file_log(loginfo)
o master_log(loginfo)

How to debug each rule individually?


 If you want to debug [Link] then execute as given below.
>python [Link] c_files/sourcefile.c
This will give all the errors individually.
 Individual and master logs will be generated.
 And we should also note that for each and every full execution all the log files will be
cleared, and new log files will be created.

Nokia internal use

You might also like