Browse Source

Code linting

Yann Weber 1 year ago
parent
commit
ea3e6c2515
10 changed files with 30 additions and 23 deletions
  1. 1
    1
      Makefile.am
  2. 1
    0
      src/asm_env.c
  3. 4
    2
      src/asmsh.c
  4. 2
    1
      src/breakpoints.c
  5. 11
    13
      src/compile.c
  6. 0
    1
      src/completion.c
  7. 1
    1
      src/shell.c
  8. 6
    0
      src/shell.h
  9. 1
    1
      src/shell_cmd_breakpoint.c
  10. 3
    3
      src/shell_cmds.c

+ 1
- 1
Makefile.am View File

@@ -43,7 +43,7 @@ endif # CHECK
43 43
 if HAVE_CPPCHECK
44 44
 LINT += cppcheck
45 45
 cppcheck:
46
-	$(CPPCHECK) --enable=all --inline-suppr --check-config --suppress=missingIncludeSystem -q $(top_builddir)/src -I $(top_builddir)/src/
46
+	$(CPPCHECK) --enable=all --inline-suppr --suppress=missingIncludeSystem -q $(top_builddir)/src -I $(top_builddir)/src/
47 47
 endif # HAVE_CPPCHECK
48 48
 
49 49
 checks: $(ALL_CHECKS)

+ 1
- 0
src/asm_env.c View File

@@ -505,6 +505,7 @@ static char *asmsh_env_tmpexec()
505 505
 		errno = err;
506 506
 		return NULL;
507 507
 	}
508
+	// cppcheck-suppress comparePointers
508 509
 	const int sz = &_binary_child_end - &_binary_child_start;
509 510
 	int rsz = write(tmpfd, &_binary_child_start, sz);
510 511
 	if(rsz<sz)

+ 4
- 2
src/asmsh.c View File

@@ -42,7 +42,7 @@ void help(const char *argv0)
42 42
 	for(size_t i=0; long_opts[i].name; i++)
43 43
 	{
44 44
 		const struct option *opt = &long_opts[i];
45
-		const char *help = help_opts[i];
45
+		const char *helptext = help_opts[i];
46 46
 		printf("\t");
47 47
 		if(opt->val)
48 48
 		{
@@ -51,7 +51,7 @@ void help(const char *argv0)
51 51
 		printf("--%s%s\n",
52 52
 				opt->name,
53 53
 				opt->has_arg==0?"":(opt->has_arg==1?"arg":"[arg]"));
54
-		printf("\t\t%s\n", help);
54
+		printf("\t\t%s\n", helptext);
55 55
 	}
56 56
 
57 57
 }
@@ -146,5 +146,7 @@ int main(int argc, char *argv[], char *envp[])
146 146
 	save_history(hpath, hstr);
147 147
 	free(hpath);
148 148
 
149
+	asmsh_logger_free(logger);
150
+
149 151
 	return ret;
150 152
 }

+ 2
- 1
src/breakpoints.c View File

@@ -138,7 +138,7 @@ int asmsh_brk_isset(asmsh_brk_t *brks, unsigned long addr)
138 138
 
139 139
 static int asmsh_brk_index(asmsh_brk_t *brks, unsigned long addr, size_t *idx)
140 140
 {
141
-	size_t beg, end, mid;
141
+	size_t beg, end;
142 142
 
143 143
 	if(brks->sz == 0)
144 144
 	{
@@ -151,6 +151,7 @@ static int asmsh_brk_index(asmsh_brk_t *brks, unsigned long addr, size_t *idx)
151 151
 	
152 152
 	while(end >= beg)
153 153
 	{
154
+		size_t mid;
154 155
 		mid = (beg + end)  / 2;
155 156
 		if(brks->addrs[mid] == addr)
156 157
 		{

+ 11
- 13
src/compile.c View File

@@ -514,12 +514,10 @@ static int text_section_informations(const int fd,
514 514
 {
515 515
 	const int off_section_off = 0x18;
516 516
 
517
-	off_t off;
518
-	ssize_t rret;
519 517
 	int err;
520 518
 	unsigned long int strtab_offset, strtab_sz;
521 519
 
522
-	if((off = lseek(fd, strtab_section_offset + off_section_off, SEEK_SET)) != \
520
+	if(lseek(fd, strtab_section_offset + off_section_off, SEEK_SET) != \
523 521
 			strtab_section_offset + off_section_off)
524 522
 	{
525 523
 		err=errno;
@@ -527,14 +525,14 @@ static int text_section_informations(const int fd,
527 525
 		errno = err;
528 526
 		return -1;
529 527
 	}
530
-	if((rret = read(fd, &strtab_offset, 8)) != 8)
528
+	if(read(fd, &strtab_offset, 8) != 8)
531 529
 	{
532 530
 		err=errno;
533 531
 		asmsh_log_perror("Unable to read strtab offset");
534 532
 		errno = err;
535 533
 		return -1;
536 534
 	}
537
-	if((rret = read(fd, &strtab_sz, 8)) != 8)
535
+	if(read(fd, &strtab_sz, 8) != 8)
538 536
 	{
539 537
 		err=errno;
540 538
 		asmsh_log_perror("Unable to read strtab size");
@@ -543,14 +541,14 @@ static int text_section_informations(const int fd,
543 541
 	}
544 542
 
545 543
 	char strtab[strtab_sz];
546
-	if((off = lseek(fd, strtab_offset, SEEK_SET)) != strtab_offset)
544
+	if(lseek(fd, strtab_offset, SEEK_SET) != strtab_offset)
547 545
 	{
548 546
 		err=errno;
549 547
 		asmsh_log_perror("Unable to seek at strtab");
550 548
 		errno = err;
551 549
 		return -1;
552 550
 	}
553
-	if((rret = read(fd, strtab, strtab_sz)) != strtab_sz)
551
+	if(read(fd, strtab, strtab_sz) != strtab_sz)
554 552
 	{
555 553
 		err=errno;
556 554
 		asmsh_log_perror("Unable to read strtab");
@@ -562,7 +560,7 @@ static int text_section_informations(const int fd,
562 560
 	for(unsigned short i=0; i<section_header_count; i++)
563 561
 	{
564 562
 		unsigned long int cur_off = section_header_off + i*section_header_sz;
565
-		if((off = lseek(fd, cur_off, SEEK_SET)) != cur_off)
563
+		if(lseek(fd, cur_off, SEEK_SET) != cur_off)
566 564
 		{
567 565
 			err=errno;
568 566
 			asmsh_log_perror("Unable to seek section");
@@ -570,7 +568,7 @@ static int text_section_informations(const int fd,
570 568
 			return -1;
571 569
 		}
572 570
 		unsigned int name_off;
573
-		if((rret = read(fd, &name_off, 4)) != 4)
571
+		if(read(fd, &name_off, 4) != 4)
574 572
 		{
575 573
 			err=errno;
576 574
 			asmsh_log_perror("Unable to read section's name offset");
@@ -593,7 +591,7 @@ static int text_section_informations(const int fd,
593 591
 			continue;
594 592
 		}
595 593
 		unsigned int type;
596
-		if((rret = read(fd, &type, 4)) != 4)
594
+		if(read(fd, &type, 4) != 4)
597 595
 		{
598 596
 			err=errno;
599 597
 			asmsh_log_perror("Unable to read section type");
@@ -607,7 +605,7 @@ static int text_section_informations(const int fd,
607 605
 			return -1;
608 606
 		}
609 607
 
610
-		if((off = lseek(fd, cur_off + off_section_off, SEEK_SET)) != \
608
+		if(lseek(fd, cur_off + off_section_off, SEEK_SET) != \
611 609
 				cur_off + off_section_off)
612 610
 		{
613 611
 			err=errno;
@@ -616,14 +614,14 @@ static int text_section_informations(const int fd,
616 614
 			return -1;
617 615
 		}
618 616
 
619
-		if((rret = read(fd, text_off, 8)) != 8)
617
+		if(read(fd, text_off, 8) != 8)
620 618
 		{
621 619
 			err=errno;
622 620
 			asmsh_log_perror("Unable to read .text section offset");
623 621
 			errno = err;
624 622
 			return -1;
625 623
 		}
626
-		if((rret = read(fd, text_sz, 8)) != 8)
624
+		if(read(fd, text_sz, 8) != 8)
627 625
 		{
628 626
 			err=errno;
629 627
 			asmsh_log_perror("Unable to read .text section size");

+ 0
- 1
src/completion.c View File

@@ -38,7 +38,6 @@ char **asmsh_completion(const char *buf, const char *text, int start, int end)
38 38
 			return NULL;
39 39
 		}
40 40
 		cmds=ptr;
41
-		ptr=&cmds[clen];
42 41
 		memcpy(&cmds[clen], instr, ilen*sizeof(*instr));
43 42
 		cmds[ilen+clen]=NULL;
44 43
 		return cmds;

+ 1
- 1
src/shell.c View File

@@ -264,7 +264,7 @@ size_t asmsh_parse_labels(asmsh_t *sh, char preffix, const char *cmd,
264 264
 			return 0;
265 265
 		}
266 266
 
267
-		const char fmt_addr[] = ". %c 0x%lx";
267
+		const char fmt_addr[] = ". %c 0x%zx";
268 268
 		char sign = sym->addr > sh->env->regs.rip ? '+': '-';
269 269
 		size_t offset = sym->addr > sh->env->regs.rip ?  \
270 270
 				sym->addr - sh->env->regs.rip:\

+ 6
- 0
src/shell.h View File

@@ -27,6 +27,10 @@
27 27
 typedef struct asmsh_s asmsh_t;
28 28
 #include "shell_sym.h"
29 29
 
30
+/** Structure storing all information needed to run a shell
31
+ * @todo Make it handle command history
32
+ * @todo Make it handle "modes" for function writing etc.
33
+ */
30 34
 struct asmsh_s
31 35
 {
32 36
 	///! Compilation context
@@ -39,6 +43,8 @@ struct asmsh_s
39 43
 	 * @deprecated
40 44
 	 */
41 45
 	char *child_path;
46
+
47
+
42 48
 	/** May store the last executed instruction ? not sure if used or not */
43 49
 	char *last_instr;
44 50
 	/** Last executed bytecode ? */

+ 1
- 1
src/shell_cmd_breakpoint.c View File

@@ -224,7 +224,7 @@ static int brk_ls(asmsh_t *sh, asmsh_cmd_args_t *args, int expr_first)
224 224
 	{
225 225
 		printf("0x%016lx\n", sh->env->brks.addrs[i]);
226 226
 	}
227
-	printf("%ld breakpoints\n", sh->env->brks.sz);
227
+	printf("%zu breakpoints\n", sh->env->brks.sz);
228 228
 	return 0;
229 229
 }
230 230
 

+ 3
- 3
src/shell_cmds.c View File

@@ -239,7 +239,7 @@ int asmsh_cmd_label(asmsh_t *sh, asmsh_cmd_args_t *args)
239 239
 			asmsh_log_info("Use '.label NAME [addr]' to define a label");
240 240
 			return 0;
241 241
 		}
242
-		printf("%3ld labels :\n", sh->env->labels.syms_sz);
242
+		printf("%3zu labels :\n", sh->env->labels.syms_sz);
243 243
 		for(size_t i=0; i<sh->env->labels.syms_sz; i++)
244 244
 		{
245 245
 			printf("\t%c%s\t %016lx\n",
@@ -312,7 +312,7 @@ int asmsh_cmd_maps(asmsh_t *sh, asmsh_cmd_args_t *args)
312 312
 	for(int i=0; i<sh->env->mmap.size; i++)
313 313
 	{
314 314
 		const child_mmap_t *m = &sh->env->mmap.maps[i];
315
-		printf("%012llx-%012llx %c%c%c  %08lx  %02lx:%02lx %10lu %s\n",
315
+		printf("%012llx-%012llx %c%c%c  %08zx  %02lx:%02lx %10lu %s\n",
316 316
 				(unsigned long long int)m->start,
317 317
 				(unsigned long long int)m->stop,
318 318
 				m->perm & PROT_READ ?'r':'-',
@@ -401,7 +401,7 @@ int asmsh_cmd_syscalls(asmsh_t *sh, asmsh_cmd_args_t *args)
401 401
 	printed = 0;
402 402
 	for(int i=0; i<sz; i++)
403 403
 	{
404
-		int ret = snprintf(buf, 512, "%3d 0x%03x %20s ",
404
+		int ret = snprintf(buf, 512, "%3u 0x%03x %20s ",
405 405
 			syscall_infos[i].nr,
406 406
 			syscall_infos[i].nr,
407 407
 			syscall_infos[i].name);

Loading…
Cancel
Save