C-check-patch
Step 1 : Download checkpatch.pl from this link - checkpatch_link |
|
---|---|
Step 2 : Add executable permission to checkpatch.pl |
|
---|---|
sudo chmod +x ./checkpatch.pl
|
Step 3 : Create a sample.c |
|
---|---|
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MIN 2
#define MAX 10
#define MEM_SIZE 8
#define REALLC_S 12
#define DATA_S 20
#define ARR_S 3
#define FOUR 4
void test_1()
{
char *str = "Hello world!";
char ch = 'l';
char *pos;
/*strchr*/
if (pos = strchr(str, ch)) {
printf("'%c' is found at pos '%ld' in string \"%s\"\n",
ch, pos-str, str);
} else {
printf("The char %c Not found in \"%s\"\n", ch, str);
}
}
void test_2(){
char *str="Hello world!\0";
char ch='l';
char *ptr=&ch;
char *pos= strchr("Hello world!\0",*ptr);
printf("%ld\n",pos-str);
}
void test_3(){
char *p,*k,**q;
char a[DATA_S]="bangaloreo";
char b='o';
k=&b;
p=&a[0];
q=&p;
char *v=strchr(*q,*k);
printf("%ld\n",v-a);
}
|
Step 4 : Run checkpatch.pl on sample.c program |
|
---|---|
sudo ./checkpatch.pl --no-tree -f sample.c
|
Step 5 : Errors/Warnings from checkpatch.pl |
|
---|---|
ERROR: Bad function definition - void test_1() should probably be void test_1(void)
#12: FILE: b.c:12:
+void test_1()
ERROR: code indent should use tabs where possible
#14: FILE: b.c:14:
+ char *str = "Hello world!";$
WARNING: please, no spaces at the start of a line
#14: FILE: b.c:14:
+ char *str = "Hello world!";$
ERROR: code indent should use tabs where possible
#16: FILE: b.c:16:
+ char ch = 'l';$
WARNING: please, no spaces at the start of a line
#16: FILE: b.c:16:
+ char ch = 'l';$
ERROR: code indent should use tabs where possible
#18: FILE: b.c:18:
+ char *pos;$
WARNING: please, no spaces at the start of a line
#18: FILE: b.c:18:
+ char *pos;$
ERROR: code indent should use tabs where possible
#21: FILE: b.c:21:
+ /*strchr*/$
ERROR: code indent should use tabs where possible
#22: FILE: b.c:22:
+ if (pos = strchr(str, ch)) {$
WARNING: please, no spaces at the start of a line
#22: FILE: b.c:22:
+ if (pos = strchr(str, ch)) {$
ERROR: do not use assignment in if condition
#22: FILE: b.c:22:
+ if (pos = strchr(str, ch)) {
ERROR: code indent should use tabs where possible
#23: FILE: b.c:23:
+ printf("'%c' is found at pos '%ld' in string \"%s\"\n",$
WARNING: please, no spaces at the start of a line
#23: FILE: b.c:23:
+ printf("'%c' is found at pos '%ld' in string \"%s\"\n",$
ERROR: code indent should use tabs where possible
#24: FILE: b.c:24:
+ ch, pos-str, str);$
WARNING: please, no spaces at the start of a line
#24: FILE: b.c:24:
+ ch, pos-str, str);$
ERROR: code indent should use tabs where possible
#25: FILE: b.c:25:
+ } else {$
WARNING: please, no spaces at the start of a line
#25: FILE: b.c:25:
+ } else {$
ERROR: code indent should use tabs where possible
#26: FILE: b.c:26:
+ printf("The char %c Not found in \"%s\"\n", ch, str);$
WARNING: please, no spaces at the start of a line
#26: FILE: b.c:26:
+ printf("The char %c Not found in \"%s\"\n", ch, str);$
ERROR: code indent should use tabs where possible
#27: FILE: b.c:27:
+ }$
WARNING: please, no spaces at the start of a line
#27: FILE: b.c:27:
+ }$
ERROR: Bad function definition - void test_2() should probably be void test_2(void)
#30: FILE: b.c:30:
+void test_2(){
ERROR: open brace '{' following function definitions go on the next line
#30: FILE: b.c:30:
+void test_2(){
ERROR: space required before the open brace '{'
#30: FILE: b.c:30:
+void test_2(){
ERROR: spaces required around that '=' (ctx:VxV)
#32: FILE: b.c:32:
+ char *str="Hello world!\0";
^
ERROR: spaces required around that '=' (ctx:VxV)
#34: FILE: b.c:34:
+ char ch='l';
^
ERROR: spaces required around that '=' (ctx:VxO)
#36: FILE: b.c:36:
+ char *ptr=&ch;
^
ERROR: space required before that '&' (ctx:OxV)
#36: FILE: b.c:36:
+ char *ptr=&ch;
^
ERROR: spaces required around that '=' (ctx:VxW)
#38: FILE: b.c:38:
+ char *pos= strchr("Hello world!\0",*ptr);
^
ERROR: space required after that ',' (ctx:VxO)
#38: FILE: b.c:38:
+ char *pos= strchr("Hello world!\0",*ptr);
^
ERROR: space required before that '*' (ctx:OxV)
#38: FILE: b.c:38:
+ char *pos= strchr("Hello world!\0",*ptr);
^
ERROR: space required after that ',' (ctx:VxV)
#40: FILE: b.c:40:
+ printf("%ld\n",pos-str);
^
ERROR: Bad function definition - void test_3() should probably be void test_3(void)
#43: FILE: b.c:43:
+void test_3(){
ERROR: open brace '{' following function definitions go on the next line
#43: FILE: b.c:43:
+void test_3(){
ERROR: space required before the open brace '{'
#43: FILE: b.c:43:
+void test_3(){
ERROR: space required after that ',' (ctx:VxO)
#45: FILE: b.c:45:
+ char *p,*k,**q;
^
ERROR: space required before that '*' (ctx:OxV)
#45: FILE: b.c:45:
+ char *p,*k,**q;
^
ERROR: space required after that ',' (ctx:VxO)
#45: FILE: b.c:45:
+ char *p,*k,**q;
^
ERROR: space required before that '*' (ctx:OxO)
#45: FILE: b.c:45:
+ char *p,*k,**q;
^
ERROR: spaces required around that '=' (ctx:VxV)
#47: FILE: b.c:47:
+ char a[DATA_S]="bangaloreo";
^
ERROR: spaces required around that '=' (ctx:VxV)
#49: FILE: b.c:49:
+ char b='o';
^
ERROR: spaces required around that '=' (ctx:VxO)
#51: FILE: b.c:51:
+ k=&b;
^
ERROR: space required before that '&' (ctx:OxV)
#51: FILE: b.c:51:
+ k=&b;
^
ERROR: spaces required around that '=' (ctx:VxO)
#52: FILE: b.c:52:
+ p=&a[0];
^
ERROR: space required before that '&' (ctx:OxV)
#52: FILE: b.c:52:
+ p=&a[0];
^
ERROR: spaces required around that '=' (ctx:VxO)
#53: FILE: b.c:53:
+ q=&p;
^
ERROR: space required before that '&' (ctx:OxV)
#53: FILE: b.c:53:
+ q=&p;
^
ERROR: spaces required around that '=' (ctx:VxV)
#55: FILE: b.c:55:
+ char *v=strchr(*q,*k);
^
ERROR: space required after that ',' (ctx:VxO)
#55: FILE: b.c:55:
+ char *v=strchr(*q,*k);
^
ERROR: space required before that '*' (ctx:OxV)
#55: FILE: b.c:55:
+ char *v=strchr(*q,*k);
^
ERROR: space required after that ',' (ctx:VxV)
#57: FILE: b.c:57:
+ printf("%ld\n",v-a);
^
total: 42 errors, 10 warnings, 59 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
NOTE: Whitespace errors detected.
You may wish to use scripts/cleanpatch or scripts/cleanfile
b.c has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
|
Step 6 : Clear all Errors/Warnings and repeat from Step 4 |
|
---|---|