From 58d595dc561f538f7e6c730ebd6ac97b999ede8b Mon Sep 17 00:00:00 2001 From: c vw Date: Tue, 28 Dec 2021 19:11:02 +0100 Subject: [PATCH] Some "polishing" (removing unused variables etc.) and other corrections that resulted from running "cppcheck" on the code. --- actions.c | 14 ++++---------- alsa_midi.c | 2 -- audio.c | 4 ++-- band.h | 3 --- client_server.c | 7 ------- discovery.c | 5 ++--- gpio.c | 13 +++++-------- i2c.c | 2 +- midi3.c | 5 ----- midi_menu.c | 9 ++------- new_protocol.c | 2 +- old_protocol.c | 2 +- radio.c | 5 ----- rigctl.c | 9 ++------- rx_menu.c | 3 ++- soapy_discovery.c | 7 +++---- soapy_protocol.c | 2 -- step_menu.c | 1 - store.c | 2 -- switch_menu.c | 5 +++-- toolbar_menu.c | 5 +++-- transmitter.c | 1 - 22 files changed, 31 insertions(+), 77 deletions(-) diff --git a/actions.c b/actions.c index 879165e..272b6f3 100644 --- a/actions.c +++ b/actions.c @@ -273,12 +273,6 @@ void schedule_action(enum ACTION action, enum ACTION_MODE mode, gint val) { int process_action(void *data) { PROCESS_ACTION *a=(PROCESS_ACTION *)data; double value; - int mode; - int id; - FILTER * band_filters=filters[vfo[active_receiver->id].mode]; - FILTER *band_filter; - FILTER *filter; - int new_val; int i; gboolean free_action=TRUE; @@ -1167,7 +1161,7 @@ int process_action(void *data) { case XIT_MINUS: if(a->mode==PRESSED) { if(can_transmit) { - double value=(double)transmitter->xit; + value=(double)transmitter->xit; value-=(double)rit_increment; if(value<-10000.0) { value=-10000.0; @@ -1175,7 +1169,7 @@ int process_action(void *data) { value=10000.0; } transmitter->xit=(int)value; - transmitter->xit_enabled=(value!=0); + transmitter->xit_enabled=(transmitter->xit!=0); if(protocol==NEW_PROTOCOL) { schedule_high_priority(); } @@ -1186,7 +1180,7 @@ int process_action(void *data) { case XIT_PLUS: if(a->mode==PRESSED) { if(can_transmit) { - double value=(double)transmitter->xit; + value=(double)transmitter->xit; value+=(double)rit_increment; if(value<-10000.0) { value=-10000.0; @@ -1194,7 +1188,7 @@ int process_action(void *data) { value=10000.0; } transmitter->xit=(int)value; - transmitter->xit_enabled=(value!=0); + transmitter->xit_enabled=(transmitter->xit!=0); if(protocol==NEW_PROTOCOL) { schedule_high_priority(); } diff --git a/alsa_midi.c b/alsa_midi.c index 80d8383..ee84394 100644 --- a/alsa_midi.c +++ b/alsa_midi.c @@ -252,7 +252,6 @@ void get_midi_devices() { snd_rawmidi_info_t *info; int card, device, subs, sub, ret; const char *devnam, *subnam; - int found=0; char portname[64]; n_midi_devices=0; @@ -299,7 +298,6 @@ void get_midi_devices() { card, device, sub, snd_strerror(ret)); break; } - if (found) break; devnam = snd_rawmidi_info_get_name(info); subnam = snd_rawmidi_info_get_subdevice_name(info); // If there is only one sub-device and it has no name, we use diff --git a/audio.c b/audio.c index 2ae6f53..4bb6eb0 100644 --- a/audio.c +++ b/audio.c @@ -424,7 +424,7 @@ int cw_audio_write(RECEIVER *rx, float sample){ break; } } else { - g_print("%s: short write lost=%d\n", __FUNCTION__, out_buffer_size - rc); + g_print("%s: short write lost=%d\n", __FUNCTION__, out_buffer_size - (int) rc); } } rx->local_audio_buffer_offset=0; @@ -538,7 +538,7 @@ int audio_write(RECEIVER *rx,float left_sample,float right_sample) { break; } } else { - g_print("%s: short write lost=%d\n", __FUNCTION__, out_buffer_size - rc); + g_print("%s: short write lost=%d\n", __FUNCTION__, out_buffer_size - (int) rc); } } rx->local_audio_buffer_offset=0; diff --git a/band.h b/band.h index b312440..23a9294 100644 --- a/band.h +++ b/band.h @@ -87,9 +87,6 @@ typedef struct _CHANNEL CHANNEL; -extern int band; -extern gboolean displayHF; - #define UK_CHANNEL_ENTRIES 11 #define OTHER_CHANNEL_ENTRIES 5 #define WRC15_CHANNEL_ENTRIES 1 diff --git a/client_server.c b/client_server.c index 600eff7..b93838e 100644 --- a/client_server.c +++ b/client_server.c @@ -193,7 +193,6 @@ void remote_audio(RECEIVER *rx,short left_sample,short right_sample) { static gint send_spectrum(void *arg) { REMOTE_CLIENT *client=(REMOTE_CLIENT *)arg; float *samples; - double sample; short s; SPECTRUM_DATA spectrum_data; gint result; @@ -1739,10 +1738,7 @@ g_print("send_mute_rx mute=%d\n",mute); static void *listen_thread(void *arg) { - int address_length; struct sockaddr_in address; - REMOTE_CLIENT* client; - int rc; int on=1; g_print("hpsdr_server: listening on port %d\n",listen_port); @@ -1855,9 +1851,6 @@ g_print("check_vfo_timer_id %d\n",check_vfo_timer_id); static void *client_thread(void* arg) { gint bytes_read; -#define MAX_BUFFER 2400 - char buffer[MAX_BUFFER]; - char *token; HEADER header; char *server=(char *)arg; diff --git a/discovery.c b/discovery.c index ed9d6fa..e24cb04 100644 --- a/discovery.c +++ b/discovery.c @@ -93,13 +93,12 @@ static gboolean start_cb (GtkWidget *widget, GdkEventButton *event, gpointer dat // we otherwise lose the information about which app has been selected. if (radio->protocol == STEMLAB_PROTOCOL) { const int device_id = radio - discovered; - int ret; if (radio->software_version & BARE_REDPITAYA) { // Start via the simple web interface - ret=alpine_start_app(gtk_combo_box_get_active_id(GTK_COMBO_BOX(apps_combobox[device_id]))); + (void) alpine_start_app(gtk_combo_box_get_active_id(GTK_COMBO_BOX(apps_combobox[device_id]))); } else { // Start via the STEMlab "bazaar" interface - ret=stemlab_start_app(gtk_combo_box_get_active_id(GTK_COMBO_BOX(apps_combobox[device_id]))); + (void) stemlab_start_app(gtk_combo_box_get_active_id(GTK_COMBO_BOX(apps_combobox[device_id]))); } // // To make this bullet-proof, we do another "discover" now diff --git a/gpio.c b/gpio.c index b70855d..7bf0fef 100644 --- a/gpio.c +++ b/gpio.c @@ -615,7 +615,6 @@ static int interrupt_cb(int event_type, unsigned int line, const struct timespec #endif void gpio_set_defaults(int ctrlr) { - int i; g_print("%s: %d\n",__FUNCTION__,ctrlr); switch(ctrlr) { case NO_CONTROLLER: @@ -670,8 +669,6 @@ void gpio_restore_state() { sprintf(name,"encoders[%d].bottom_encoder_address_b",i); value=getProperty(name); if(value) encoders[i].bottom_encoder_address_b=atoi(value); - sprintf(name,"encoders[%d].bottom_encoder_address_b",i); - value=getProperty(name); sprintf(name,"encoders[%d].top_encoder_enabled",i); value=getProperty(name); if(value) encoders[i].top_encoder_enabled=atoi(value); @@ -969,9 +966,9 @@ static int setup_output_line(struct gpiod_chip *chip, int offset, int _initial_v #endif int gpio_init() { - int ret=0; #ifdef GPIO + int ret=0; initialiseEpoch(); g_mutex_init(&encoder_mutex); @@ -1078,15 +1075,15 @@ int gpio_init() { #endif return 0; +#ifdef GPIO err: g_print("%s: err\n",__FUNCTION__); -#ifdef GPIO if(chip!=NULL) { gpiod_chip_close(chip); chip=NULL; } -#endif return ret; +#endif } void gpio_close() { @@ -1097,9 +1094,9 @@ void gpio_close() { #ifdef LOCALCW void gpio_cw_sidetone_set(int level) { +#ifdef GPIO int rc; if (ENABLE_GPIO_SIDETONE) { -#ifdef GPIO #ifdef OLD_GPIOD if((rc=gpiod_ctxless_set_value(gpio_device,SIDETONE_GPIO,level,FALSE,consumer,NULL,NULL))<0) { #else @@ -1107,8 +1104,8 @@ void gpio_cw_sidetone_set(int level) { #endif g_print("%s: err=%d\n",__FUNCTION__,rc); } -#endif } +#endif } int gpio_cw_sidetone_enabled() { diff --git a/i2c.c b/i2c.c index 4222455..a46e3f4 100644 --- a/i2c.c +++ b/i2c.c @@ -52,7 +52,7 @@ unsigned int i2c_sw[16]= static int write_byte_data(unsigned char reg, unsigned char data) { int rc; - if(i2c_smbus_write_byte_data(fd,reg,data&0xFF)<0) { + if((rc=i2c_smbus_write_byte_data(fd,reg,data&0xFF))<0) { g_print("%s: write REG_GCONF config failed: addr=%02X %s\n",__FUNCTION__,i2c_address_1,g_strerror(errno)); } diff --git a/midi3.c b/midi3.c index b018ce0..ed3f4ad 100644 --- a/midi3.c +++ b/midi3.c @@ -29,11 +29,6 @@ void DoTheMidi(int action, enum ACTIONtype type, int val) { - int new; - double dnew; - double *dp; - int *ip; - //g_print("%s: action=%d type=%d val=%d\n",__FUNCTION__,action,type,val); switch(type) { diff --git a/midi_menu.c b/midi_menu.c index 011f0e2..9c08437 100644 --- a/midi_menu.c +++ b/midi_menu.c @@ -187,9 +187,6 @@ static void update_wheelparams(gpointer user_data) { } static void type_changed_cb(GtkWidget *widget, gpointer data) { - int i=1; - int j=1; - // update actions available for the type gchar *type=gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(widget)); @@ -754,8 +751,8 @@ static void delete_cb(GtkButton *widget,gpointer user_data) { void midi_menu(GtkWidget *parent) { int i; - int col=0; - int row=0; + int col; + int row; GtkCellRenderer *renderer; GtkWidget *lbl; @@ -1138,8 +1135,6 @@ static int update(void *data) { int state=GPOINTER_TO_INT(data); gchar text[32]; gint i=1; - gint j; - switch(state) { case UPDATE_NEW: diff --git a/new_protocol.c b/new_protocol.c index 5ee92fc..15a3693 100644 --- a/new_protocol.c +++ b/new_protocol.c @@ -1932,7 +1932,7 @@ static void process_high_priority() { if (cw_keyer_internal) { // Stops CAT cw transmission if paddle hit in "internal" CW - if ((dash || dot)) cw_key_hit=1; + if (dash || dot) cw_key_hit=1; } else { #ifdef LOCALCW // diff --git a/old_protocol.c b/old_protocol.c index 242895e..da42fc0 100644 --- a/old_protocol.c +++ b/old_protocol.c @@ -869,7 +869,7 @@ static void process_control_bytes() { if (cw_keyer_internal) { // Stops CAT cw transmission if paddle hit in "internal" CW - if ((dash || dot)) cw_key_hit=1; + if (dash || dot) cw_key_hit=1; } else { #ifdef LOCALCW // diff --git a/radio.c b/radio.c index 6660b04..ea18a72 100644 --- a/radio.c +++ b/radio.c @@ -680,12 +680,9 @@ g_print("create_visual: calling radio_change_receivers: receivers=%d r=%d\n",rec void start_radio() { int i; - int y; //g_print("start_radio: selected radio=%p device=%d\n",radio,radio->device); gdk_window_set_cursor(gtk_widget_get_window(top_window),gdk_cursor_new(GDK_WATCH)); - int rc; - protocol=radio->protocol; device=radio->device; @@ -1158,7 +1155,6 @@ void start_radio() { adc[0].gain=rx_gain_calibration; adc[0].min_gain=0.0; adc[0].max_gain=100.0; - adc[0].antenna=0; dac[0].antenna=1; dac[0].gain=0; @@ -1193,7 +1189,6 @@ void start_radio() { adc[1].gain=rx_gain_calibration; adc[1].min_gain=0.0; adc[1].max_gain=100.0; - adc[1].antenna=0; dac[1].antenna=1; dac[1].gain=0; diff --git a/rigctl.c b/rigctl.c index 6f3d88a..9222f38 100644 --- a/rigctl.c +++ b/rigctl.c @@ -639,14 +639,9 @@ static gpointer rigctl_client (gpointer data) { g_mutex_unlock(&mutex_a->m); g_idle_add(ext_vfo_update,NULL); - int save_flag = 0; // Used to concatenate two cmd lines together - int semi_number = 0; int i; - char * work_ptr; - char work_buf[MAXDATASIZE]; int numbytes; char cmd_input[MAXDATASIZE] ; - char cmd_save[80]; char *command=g_new(char,MAXDATASIZE); int command_index=0; @@ -2662,7 +2657,7 @@ int parse_cmd(void *data) { break; case 'T': //CT // sets/reads CTCSS status - if(command[3]==';') { + if(command[2]==';') { sprintf(reply,"CT%d;",transmitter->ctcss_enabled); send_resp(client->fd,reply) ; } else if(command[3]==';') { @@ -3340,7 +3335,7 @@ int parse_cmd(void *data) { case 'A': //SA // set/read stallite mode status if(command[2]==';') { - sprintf(reply,"SA%d%d%d%d%d%d%dSAT? ;",sat_mode==SAT_MODE|sat_mode==RSAT_MODE,0,0,0,sat_mode==SAT_MODE,sat_mode==RSAT_MODE,0); + sprintf(reply,"SA%d%d%d%d%d%d%dSAT? ;",(sat_mode==SAT_MODE)|(sat_mode==RSAT_MODE),0,0,0,sat_mode==SAT_MODE,sat_mode==RSAT_MODE,0); send_resp(client->fd,reply); } else if(command[9]==';') { if(command[2]=='0') { diff --git a/rx_menu.c b/rx_menu.c index 105b1fd..54254f5 100644 --- a/rx_menu.c +++ b/rx_menu.c @@ -141,7 +141,7 @@ static void mute_radio_cb(GtkWidget *widget, gpointer data) { // static void local_output_changed_cb(GtkWidget *widget, gpointer data) { int i = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); - fprintf(stderr,"local_output_changed rx=%d %s\n",active_receiver->id,output_devices[i].name); + if(active_receiver->local_audio) { audio_close_output(active_receiver); // audio_close with OLD device } @@ -152,6 +152,7 @@ static void local_output_changed_cb(GtkWidget *widget, gpointer data) { } if(i>=0) { + fprintf(stderr,"local_output_changed rx=%d %s\n",active_receiver->id,output_devices[i].name); active_receiver->audio_name=g_new(gchar,strlen(output_devices[i].name)+1); strcpy(active_receiver->audio_name,output_devices[i].name); //active_receiver->audio_device=output_devices[i].index; // update rx to NEW device diff --git a/soapy_discovery.c b/soapy_discovery.c index b0ca895..88f9adc 100644 --- a/soapy_discovery.c +++ b/soapy_discovery.c @@ -106,13 +106,13 @@ static void get_info(char *driver) { } size_t rx_channels=SoapySDRDevice_getNumChannels(sdr, SOAPY_SDR_RX); - fprintf(stderr,"Rx channels: %ld\n",rx_channels); + fprintf(stderr,"Rx channels: %ld\n", (long) rx_channels); for(int i=0;iid; new_freq = mem[index].frequency; fprintf(stderr,"recall_select_cb: Index=%d\n",index); @@ -125,7 +124,6 @@ void recall_memory_slot(int index) { } void store_memory_slot(int index) { - char workstr[40]; int id=active_receiver->id; // diff --git a/switch_menu.c b/switch_menu.c index fb22a70..1be8bf7 100644 --- a/switch_menu.c +++ b/switch_menu.c @@ -77,8 +77,9 @@ static gboolean switch_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { return TRUE; } -static void response_event(GtkWidget *dialog,gint id,gpointer user_data) { - gtk_widget_destroy(dialog); +static void response_event(GtkWidget *mydialog,gint id,gpointer user_data) { + // mydialog is a copy of dialog + gtk_widget_destroy(mydialog); dialog=NULL; active_menu=NO_MENU; sub_menu=NULL; diff --git a/toolbar_menu.c b/toolbar_menu.c index 2913b44..aaeace1 100644 --- a/toolbar_menu.c +++ b/toolbar_menu.c @@ -78,8 +78,9 @@ static gboolean switch_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { return TRUE; } -static void response_event(GtkWidget *dialog,gint id,gpointer user_data) { - gtk_widget_destroy(dialog); +static void response_event(GtkWidget *mydialog,gint id,gpointer user_data) { + // mydialog is a copy of dialog + gtk_widget_destroy(mydialog); dialog=NULL; active_menu=NO_MENU; sub_menu=NULL; diff --git a/transmitter.c b/transmitter.c index c3a2b76..644fa99 100644 --- a/transmitter.c +++ b/transmitter.c @@ -1015,7 +1015,6 @@ fprintf(stderr,"transmitter: allocate buffers: mic_input_buffer=%d iq_output_buf void tx_set_mode(TRANSMITTER* tx,int mode) { if(tx!=NULL) { - int filter_low, filter_high; tx->mode=mode; SetTXAMode(tx->id, tx->mode); tx_set_filter(tx); -- 2.45.2