]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Some "polishing" (removing unused variables etc.) and other corrections
authorc vw <dl1ycf@darc.de>
Tue, 28 Dec 2021 18:11:02 +0000 (19:11 +0100)
committerc vw <dl1ycf@darc.de>
Tue, 28 Dec 2021 18:11:02 +0000 (19:11 +0100)
that resulted from running "cppcheck" on the code.

22 files changed:
actions.c
alsa_midi.c
audio.c
band.h
client_server.c
discovery.c
gpio.c
i2c.c
midi3.c
midi_menu.c
new_protocol.c
old_protocol.c
radio.c
rigctl.c
rx_menu.c
soapy_discovery.c
soapy_protocol.c
step_menu.c
store.c
switch_menu.c
toolbar_menu.c
transmitter.c

index 879165e443eb616845b46881e200c8cc974e63e0..272b6f36be7ce99563abf876021c70ec5bef6c93 100644 (file)
--- 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();
           }
index 80d8383d6ec8c78805ffe7b5d1c8700fc674ff6d..ee84394f91c82886ab928649f15fcfacae979ac0 100644 (file)
@@ -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 2ae6f53b1d7f8f7689206e3214c78673fd80f75c..4bb6eb05601b2021aef8c1b931b0899d23ea9283 100644 (file)
--- 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 b312440eb2a3d52af42dee0a60274fcd34135c9e..23a92948b364d8c13a7587fd2062cc41d65bb291 100644 (file)
--- 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
index 600eff7e506f207ca7e51fba99c376829402245b..b93838eb37ca26fd1a95299ecf9d356afaa4cc8a 100644 (file)
@@ -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;
 
index ed9d6fa16d5e9a03adbc12da0907772165b73660..e24cb04619167255c2ec5c0e3321473838d74e46 100644 (file)
@@ -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 b70855d2ffd4b1927bd60b5443790e5e553d14b6..7bf0feffc086bf4ff2e53f8e040f03eae362060f 100644 (file)
--- 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 4222455f251d869fb14b929e1d1909122db2fdcb..a46e3f4594a750c3f2950b4ce754689e3531a95a 100644 (file)
--- 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 b018ce072ff3a1601e3c71458cc22f5c15ee3a09..ed3f4ad3a1506da508c65bfa07d26e6c5ab5b32a 100644 (file)
--- a/midi3.c
+++ b/midi3.c
 
 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) {
index 011f0e2427b839011822858f704c1f2e0796bb0d..9c08437730515332e9efbe43422339fd6391834b 100644 (file)
@@ -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:
index 5ee92fca4631f1c474e2f4273946c79b36a02262..15a3693627e567e1634366f1b40f36d6f228aaf4 100644 (file)
@@ -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
       //
index 242895eb43a88aed9b5fbfbbe000b638e4826378..da42fc0843db5aa93a4e39b92c7383d67447b30a 100644 (file)
@@ -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 6660b042b1b878a473995817b3717a9da4d0d2b4..ea18a728f7b15c3fc354931eed217082fd0a0bb4 100644 (file)
--- 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;
 
index 6f3d88a34d26b62298e699a551787c72e3826863..9222f3875961336c6bddb8eddcd36490016dbfa4 100644 (file)
--- 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') {
index 105b1fd0e47eda03005a6a517c4b6495cc3aa266..54254f574067c5b5c85019db07f0e165c45106ad 100644 (file)
--- 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
index b0ca895d134a80133a645af6665373e0c434f0ab..88f9adcf5533c7bdba82a3b281f497d92aa0fcf4 100644 (file)
@@ -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;i<rx_channels;i++) {
     fprintf(stderr,"Rx channel full duplex: channel=%d fullduplex=%d\n",i,SoapySDRDevice_getFullDuplex(sdr, SOAPY_SDR_RX, i));
   }
 
   size_t tx_channels=SoapySDRDevice_getNumChannels(sdr, SOAPY_SDR_TX);
-  fprintf(stderr,"Tx channels: %ld\n",tx_channels);
+  fprintf(stderr,"Tx channels: %ld\n", (long) tx_channels);
   for(int i=0;i<tx_channels;i++) {
     fprintf(stderr,"Tx channel full duplex: channel=%d fullduplex=%d\n",i,SoapySDRDevice_getFullDuplex(sdr, SOAPY_SDR_TX, i));
   }
@@ -303,9 +303,8 @@ fprintf(stderr,"Rx gains: \n");
 
 void soapy_discovery() {
   size_t length;
-  int i,j;
+  int i;
   SoapySDRKwargs input_args={};
-  SoapySDRKwargs args={};
 
 fprintf(stderr,"%s\n",__FUNCTION__);
   rtlsdr_count=0;
index a948954e8402878f25605ba25612ce0685a9334a..39435b237836776ec8c8d345af660837b087669b 100644 (file)
@@ -268,8 +268,6 @@ fprintf(stderr,"soapy_protocol_stop_transmitter: deactivateStream\n");
 void soapy_protocol_init(gboolean hf) {
   SoapySDRKwargs args={};
   char temp[32];
-  int rc;
-  int i;
 
 
   SoapySDR_setLogLevel(SOAPY_SDR_TRACE);
index da12f0361a8e5db2dbc046926eea8cebc8ba02b3..769308752536224a0c2dd9fde1fcf5f3030c815c 100644 (file)
@@ -51,7 +51,6 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d
 }
 
 static void step_select_cb (GtkToggleButton *widget, gpointer        data) {
-  int val=GPOINTER_TO_INT(data);
   if(gtk_toggle_button_get_active(widget)) {
     vfo_set_step_from_index(GPOINTER_TO_INT(data));
     g_idle_add(ext_vfo_update,NULL);
diff --git a/store.c b/store.c
index 68fc5007295fbdc9b9228793927c7acd2037f760..0c7be6faed354dffc104e0c6acbf8ca7e4ac5618 100644 (file)
--- a/store.c
+++ b/store.c
@@ -97,7 +97,6 @@ void memRestoreState() {
 
 void recall_memory_slot(int index) {
     long long new_freq;
-    int id=active_receiver->id;
 
     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;
 
    //
index fb22a7099bf580d5dc8276d59b696873fea72fe4..1be8bf71f1871a18f2e53df16e8e745b203db6d3 100644 (file)
@@ -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;
index 2913b44dd5100ddc6fcb1f009606be8a1a6bea40..aaeace1b039f98f46afa32d481b9a6e43023d89b 100644 (file)
@@ -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;
index c3a2b76be222319c217a6c50132ff4c5b1f565f7..644fa995e388243069261950d9a3a354759aa058 100644 (file)
@@ -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);