From e0313cecbd2588ebc3a1e0ddeeeed780698e1a49 Mon Sep 17 00:00:00 2001 From: Cary R Date: Sat, 2 Jan 2021 13:39:20 -0800 Subject: [PATCH] Update driver and acc/tf directories with changes suggested by cppcheck --- driver-vpi/main.c | 8 ++++---- driver/cflexor.lex | 14 +++++++------- driver/main.c | 2 -- libveriuser/a_configure.c | 7 ++----- libveriuser/cppcheck.sup | 30 +++++++++++++++--------------- 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/driver-vpi/main.c b/driver-vpi/main.c index 19ed5cbe7..3b1906682 100644 --- a/driver-vpi/main.c +++ b/driver-vpi/main.c @@ -1,6 +1,6 @@ /* + * Copyright (c) 2015-2021 Martin Whitaker * Copyright (c) 2002 Gus Baldauf (gus@picturel.com) - * Copyright (c) 2015 Martin Whitaker * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -241,13 +241,13 @@ static int GetRegistryKey(char *key, char **value) lrv = RegQueryValueEx(hkKey, key, NULL, ®KeyType, NULL, ®KeySize); if ((lrv != ERROR_SUCCESS) || (regKeyType != REG_SZ) || (!regKeySize)) { - lrv = RegCloseKey(hkKey); + RegCloseKey(hkKey); return 0; } regKeyBuffer = (char *) malloc(regKeySize+1); if (!regKeyBuffer) { - lrv = RegCloseKey(hkKey); + RegCloseKey(hkKey); fprintf(stderr, "error: out of memory\n"); myExit(4); } @@ -257,7 +257,7 @@ static int GetRegistryKey(char *key, char **value) lrv = RegQueryValueEx(hkKey, key, NULL, ®KeyType, (unsigned char *) regKeyBuffer, ®KeySize); if ((lrv != ERROR_SUCCESS) || (regKeyType != REG_SZ) || (!regKeySize)) { - lrv = RegCloseKey(hkKey); + RegCloseKey(hkKey); free(regKeyBuffer); return 0; } diff --git a/driver/cflexor.lex b/driver/cflexor.lex index 15ef9dc3a..68447cdc7 100644 --- a/driver/cflexor.lex +++ b/driver/cflexor.lex @@ -4,7 +4,7 @@ %{ /* - * Copyright (c) 2001-2017 Stephen Williams (steve@icarus.com) + * Copyright (c) 2001-2021 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -71,7 +71,7 @@ int cmdfile_stack_ptr = 0; \n { cflloc.first_line += 1; BEGIN(comment_enter); } <> { - fprintf(stderr, "%s:%d: ERROR: Comment not terminated.\n", + fprintf(stderr, "%s:%u: ERROR: Comment not terminated.\n", current_file, cflloc.first_line); command_file_errors += 1; BEGIN(0); @@ -84,7 +84,7 @@ int cmdfile_stack_ptr = 0; "*/" { BEGIN(comment_enter); } <> { - fprintf(stderr, "%s:%d: ERROR: Comment not terminated.\n", + fprintf(stderr, "%s:%u: ERROR: Comment not terminated.\n", current_file, cflloc.first_line); command_file_errors += 1; BEGIN(0); @@ -146,7 +146,7 @@ int cmdfile_stack_ptr = 0; <> { BEGIN(0); - fprintf(stderr, "%s:%d: ERROR: Plusargs statement not terminated.\n", + fprintf(stderr, "%s:%u: ERROR: Plusargs statement not terminated.\n", current_file, cflloc.first_line); command_file_errors += 1; PROCESS_EOF } @@ -194,7 +194,7 @@ int cmdfile_stack_ptr = 0; <> { cflval.text = trim_trailing_white(yytext, 0); BEGIN(0); - fprintf(stderr, "%s:%d: ERROR: File name not terminated.\n", + fprintf(stderr, "%s:%u: ERROR: File name not terminated.\n", current_file, cflloc.first_line); command_file_errors += 1; PROCESS_EOF } @@ -233,7 +233,7 @@ void switch_to_command_file(const char *file) if (cmdfile_stack_ptr >= MAX_CMDFILE_DEPTH) { fprintf(stderr, "Error: command files nested too deeply (%d) " - "at %s:%d.\n", MAX_CMDFILE_DEPTH, current_file, + "at %s:%u.\n", MAX_CMDFILE_DEPTH, current_file, cflloc.first_line); exit(1); } @@ -260,7 +260,7 @@ void switch_to_command_file(const char *file) yyin = fopen(path, "r"); if (yyin == NULL) { fprintf(stderr, "Error: unable to read nested command file (%s) " - "at %s:%d.\n", path, current_file, cflloc.first_line); + "at %s:%u.\n", path, current_file, cflloc.first_line); exit(1); } diff --git a/driver/main.c b/driver/main.c index 7fbc52f24..bb05e4144 100644 --- a/driver/main.c +++ b/driver/main.c @@ -382,7 +382,6 @@ static int t_preprocess_only(void) snprintf(tmp, sizeof tmp, " > \"%s\"", opath); cmd = realloc(cmd, ncmd+strlen(tmp)+1); strcpy(cmd+ncmd, tmp); - ncmd += strlen(tmp); } if (verbose_flag) @@ -483,7 +482,6 @@ static int t_compile(void) rc = strlen(tmp); cmd = realloc(cmd, ncmd+rc+1); strcpy(cmd+ncmd, tmp); - ncmd += rc; if (verbose_flag) diff --git a/libveriuser/a_configure.c b/libveriuser/a_configure.c index cd79ca1e5..fe02d7541 100644 --- a/libveriuser/a_configure.c +++ b/libveriuser/a_configure.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2009 Stephen Williams (steve@icarus.com) + * Copyright (c) 2003-2021 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -44,21 +44,18 @@ int acc_configure(PLI_INT32 config_param, const char*value) value); } - rc = 1; + rc = 0; if (strcmp(value,"acc_set_scope") == 0) { vpi_printf("XXXX acc_configure argument: Sorry: " "(accEnableArgs, %s\n", value); - rc = 0; } else if (strcmp(value,"no_acc_set_scope") == 0) { vpi_printf("XXXX acc_configure argument: Sorry: " "(accEnableArgs, %s\n", value); - rc = 0; } else { vpi_printf("XXXX acc_configure argument error. " "(accEnableArgs, %s(invalid)\n", value); - rc = 0; } break; diff --git a/libveriuser/cppcheck.sup b/libveriuser/cppcheck.sup index 3fd3b2bb5..446383c12 100644 --- a/libveriuser/cppcheck.sup +++ b/libveriuser/cppcheck.sup @@ -59,7 +59,7 @@ unusedFunction:a_handle_parent.c:34 // acc_handle_simulated_net() unusedFunction:a_handle_simulated_net.c:26 // acc_handle_tfarg() -unusedFunction:a_handle_tfarg.c:26 +unusedFunction:a_handle_tfarg.c:27 // acc_handle_tfinst() unusedFunction:a_handle_tfarg.c:53 @@ -79,7 +79,7 @@ unusedFunction:a_next_topmod.c:30 unusedFunction:a_product_version.c:23 // acc_set_scope() -unusedFunction:a_handle_object.c:40 +unusedFunction:a_handle_object.c:39 // acc_set_value() unusedFunction:a_set_value.c:27 @@ -115,7 +115,7 @@ unusedFunction:exprinfo.c:26 // tf_getcstringp() unusedFunction:getcstringp.c:26 // tf_getlongp() -unusedFunction:getlongp.c:29 +unusedFunction:getlongp.c:30 // tf_getlongtime() unusedFunction:getsimtime.c:112 // tf_getp() @@ -125,25 +125,25 @@ unusedFunction:getp.c:120 // tf_gettime() unusedFunction:getsimtime.c:77 // tf_getworkarea() -unusedFunction:workarea.c:62 +unusedFunction:workarea.c:61 // tf_igettimeprecision() -unusedFunction:getsimtime.c:198 +unusedFunction:getsimtime.c:196 // tf_igettimeunit() -unusedFunction:getsimtime.c:228 +unusedFunction:getsimtime.c:226 // tf_long_to_real() unusedFunction:math.c:47 // tf_message() unusedFunction:io_print.c:56 // tf_mipname() -unusedFunction:spname.c:47 +unusedFunction:spname.c:46 // tf_multiply_long() unusedFunction:math.c:27 // tf_nodeinfo() unusedFunction:nodeinfo.c:27 // tf_nump() -unusedFunction:nump.c:42 +unusedFunction:nump.c:43 // tf_putlongp() -unusedFunction:putlongp.c:28 +unusedFunction:putlongp.c:29 // tf_putp() unusedFunction:putp.c:88 // tf_putrealp() @@ -151,7 +151,7 @@ unusedFunction:putp.c:137 // tf_real_to_long() unusedFunction:math.c:40 // tf_rosynchronize() -unusedFunction:veriusertfs.c:391 +unusedFunction:veriusertfs.c:433 // tf_scale_longdelay() unusedFunction:getsimtime.c:136 // tf_scale_realdelay() @@ -159,9 +159,9 @@ unusedFunction:getsimtime.c:161 // tf_setdelay() unusedFunction:delay.c:75 // tf_setrealdelay() -unusedFunction:veriusertfs.c:426 +unusedFunction:veriusertfs.c:468 // tf_setworkarea() -unusedFunction:workarea.c:36 +unusedFunction:workarea.c:37 // tf_spname() unusedFunction:spname.c:25 // tf_strgetp() @@ -169,9 +169,9 @@ unusedFunction:getp.c:177 // tf_strgettime() unusedFunction:getsimtime.c:85 // tf_synchronize() -unusedFunction:veriusertfs.c:364 +unusedFunction:veriusertfs.c:406 // tf_typep() -unusedFunction:typep.c:24 +unusedFunction:typep.c:25 // tf_unscale_longdelay() unusedFunction:getsimtime.c:144 // tf_unscale_realdelay() @@ -184,4 +184,4 @@ unusedFunction:io_print.c:34 // tf_getlongsimtime() unusedFunction:getsimtime.c:126 // veriusertfs_register_table() -unusedFunction:veriusertfs.c:76 +unusedFunction:veriusertfs.c:93