speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix most warnings with gcc 4.4 on Linux.


From: Boris Dusek
Subject: [PATCH] Fix most warnings with gcc 4.4 on Linux.
Date: Tue, 7 Sep 2010 14:33:05 +0200

---
 src/audio/alsa.c                |    5 ++++-
 src/audio/oss.c                 |    4 ++--
 src/audio/pulse.c               |    3 +--
 src/c/api/libspeechd.c          |    1 -
 src/c/clients/spdsend/server.c  |    9 ++++++---
 src/c/clients/spdsend/spdsend.c |    5 +++--
 src/modules/cicero.c            |    7 +++++--
 src/modules/espeak.c            |    2 +-
 src/modules/festival.c          |    2 +-
 src/modules/festival_client.c   |    8 ++++----
 src/modules/flite.c             |    2 ++
 src/modules/module_utils.c      |    8 ++++----
 src/server/options.c            |   19 +++++++++++++++++++
 src/server/options.h            |   18 ++----------------
 src/server/parse.c              |    3 ++-
 src/server/sem_functions.c      |    4 +++-
 src/server/speaking.c           |    8 ++++++--
 src/tests/run_test.c            |    7 +++++--
 18 files changed, 70 insertions(+), 45 deletions(-)

diff --git a/src/audio/alsa.c b/src/audio/alsa.c
index 12da8ea..062f3ea 100644
--- a/src/audio/alsa.c
+++ b/src/audio/alsa.c
@@ -318,7 +318,7 @@ int wait_for_poll(spd_alsa_id_t *id, struct pollfd 
*alsa_poll_fds,
 
            /* Check for stop request from alsa_stop on the last file
               descriptors*/
-           if (revents = id->alsa_poll_fds[count-1].revents){
+           if ((revents = id->alsa_poll_fds[count-1].revents)){
                if (revents & POLLIN){
                    MSG(4, "wait_for_poll: stop requested");
                    return 1;
@@ -493,6 +493,9 @@ alsa_play(AudioID *id, AudioTrack track)
             case SPD_AUDIO_BE:
                 format = SND_PCM_FORMAT_S16_BE;
                 break;
+            default:
+                ERR("unknown audio format (%d)", alsa_id->id.format);
+                return -1;
         }
        bytes_per_sample = 2;
     }else if (track.bits == 8){
diff --git a/src/audio/oss.c b/src/audio/oss.c
index 5ae1203..4254b60 100644
--- a/src/audio/oss.c
+++ b/src/audio/oss.c
@@ -189,7 +189,7 @@ oss_play(AudioID *id, AudioTrack track)
     struct timeval now;
     struct timespec timeout;
     float lenght;
-    int r;
+    int r = 0;
     int format, oformat, channels, speed;
     int bytes_per_sample;
     int num_bytes;
@@ -423,7 +423,7 @@ oss_play(AudioID *id, AudioTrack track)
 static int
 oss_stop(AudioID *id)
 {
-    int ret;
+    int ret = 0;
     spd_oss_id_t * oss_id = (spd_oss_id_t *)id;
 
     if (oss_id == NULL) return 0;
diff --git a/src/audio/pulse.c b/src/audio/pulse.c
index 90d2c9f..f4d4c12 100644
--- a/src/audio/pulse.c
+++ b/src/audio/pulse.c
@@ -63,10 +63,9 @@ typedef struct {
 static int pulse_log_level;
 static char const * pulse_play_cmd="paplay";
 
-static FILE *pulseDebugFile = NULL;
-
 /* Write to /tmp/speech-dispatcher-pulse.log */
 #ifdef DEBUG_PULSE
+static FILE *pulseDebugFile = NULL;
 static void MSG(char *message, ...)
 {
     va_list ap;
diff --git a/src/c/api/libspeechd.c b/src/c/api/libspeechd.c
index 1c9474d..5d4a65a 100644
--- a/src/c/api/libspeechd.c
+++ b/src/c/api/libspeechd.c
@@ -284,7 +284,6 @@ spawn_server(SPDConnectionAddress *address, int 
is_localhost, gchar **spawn_erro
     GError *gerror = NULL;
     int exit_status;
     int i;
-    char *resolved_ip;
 
     if ((address->method==SPD_METHOD_INET_SOCKET) && (!is_localhost)){
        *spawn_error = g_strdup("Spawn failed, the given network address 
doesn't seem to be on localhost");
diff --git a/src/c/clients/spdsend/server.c b/src/c/clients/spdsend/server.c
index 83e3afd..1b45f01 100644
--- a/src/c/clients/spdsend/server.c
+++ b/src/c/clients/spdsend/server.c
@@ -293,8 +293,8 @@ static void process_data (Stream s)
   else
     report_error (s);
 
-  do_send_data (id, s, NONE, forward_data) == OK &&
-  do_send_data (id, NONE, s, forward_ssip_answer) == OK;
+  if (do_send_data (id, s, NONE, forward_data) == OK)
+    do_send_data (id, NONE, s, forward_ssip_answer);
 }
 
 
@@ -392,13 +392,16 @@ static void serve ()
 
 static void daemonize ()
 {
+  int ret = 0;
   if (fork () != 0)
     exit (0);
   setsid ();
   signal (SIGHUP, SIG_IGN);
   if (fork () != 0)
     exit (0);
-  chdir ("/");
+  if ((ret = chdir ("/")) != 0)
+    fputs("server.c:daemonize: could not chdir", stderr);
+    exit (1);
   umask (0);
   {
     int i;
diff --git a/src/c/clients/spdsend/spdsend.c b/src/c/clients/spdsend/spdsend.c
index f459e55..cb50249 100644
--- a/src/c/clients/spdsend/spdsend.c
+++ b/src/c/clients/spdsend/spdsend.c
@@ -117,7 +117,8 @@ int main (int argc, char **argv)
         exit (EXIT_OK);
       }
     
-    if (! strcmp (action, "--open"))
+    const bool action_is_open = strcmp (action, "--open") == 0;
+    if (action_is_open)
       {
         if (argc != 4)
           usage ("Invalid number of arguments");
@@ -144,7 +145,7 @@ int main (int argc, char **argv)
         return EXIT_ERROR;
       
       {
-        int result = (! strcmp (action, "--open")
+        int result = (action_is_open
                       ? open_connection (server, host, port)
                       : function (server, conn_id));
         return (result == OK ? EXIT_OK : EXIT_ERROR);
diff --git a/src/modules/cicero.c b/src/modules/cicero.c
index 4555b74..5615b7a 100644
--- a/src/modules/cicero.c
+++ b/src/modules/cicero.c
@@ -51,9 +51,11 @@ static unsigned int CiceroMaxChunkLength = 500;
 
 /* Internal functions prototypes */
 static void cicero_set_rate(signed int rate);
+/*
 static void cicero_set_pitch(signed int pitch);
 static void cicero_set_volume(signed int pitch);
 static void cicero_set_voice(EVoiceType voice);
+*/
 
 static void* _cicero_speak(void*);
 
@@ -394,7 +396,7 @@ _cicero_speak(void* nothing)
              break;
            }
            if (ret > 0)
-             read(fd1[0], b, 2);
+             TEMP_FAILURE_RETRY(read(fd1[0], b, 2));
            if (cicero_stop) {
              cicero_speaking = 0;
              module_report_event_stop();
@@ -465,7 +467,7 @@ cicero_set_rate(signed int rate)
   mywrite(fd2[1], l, 5);
 }
 
-
+/*
 static void
 cicero_set_pitch(signed int pitch)
 {
@@ -475,5 +477,6 @@ static void
 cicero_set_voice(EVoiceType voice)
 {
 }
+*/
 
 #include "module_main.c"
diff --git a/src/modules/espeak.c b/src/modules/espeak.c
index be96cd2..ea0d076 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -347,7 +347,7 @@ module_speak(gchar *data, size_t bytes, EMessageType 
msgtype)
          pthread_mutex_unlock(&espeak_state_mutex);
          return FATAL_ERROR;
        }
-       DBG("Espeak: Requested data: |%s| %d %ld", data, msgtype, bytes);
+       DBG("Espeak: Requested data: |%s| %d %ld", data, msgtype, (long) bytes);
 
        espeak_state_reset();
        espeak_state = BEFORE_SYNTH;
diff --git a/src/modules/festival.c b/src/modules/festival.c
index 11becbc..d543a5c 100644
--- a/src/modules/festival.c
+++ b/src/modules/festival.c
@@ -835,7 +835,7 @@ cache_clean(size_t new_element_size)
     GList *gl;
     TCounterEntry *centry;
 
-    DBG("Cache: cleaning, cache size %ld kbytes (>max %d).", 
FestivalCache.size/1024,
+    DBG("Cache: cleaning, cache size %ld kbytes (>max %d).", (long) 
(FestivalCache.size/1024),
         FestivalCacheMaxKBytes);
 
     req_size = 2*FestivalCache.size/3;
diff --git a/src/modules/festival_client.c b/src/modules/festival_client.c
index a9e1b4e..913c584 100644
--- a/src/modules/festival_client.c
+++ b/src/modules/festival_client.c
@@ -436,8 +436,8 @@ festival_accept_any_response(FT_Info *info)
         char *str; \
         fd = fdopen(dup(info->server_fd),"wb"); \
         if (fd != NULL){ \
-          str = g_strdup_printf(format"\n"); \
-          fprintf(fd, str); \
+          str = g_strdup(format"\n"); \
+          fputs(str, fd); \
           DBG("-> Festival: |%s|", str); \
           free(str); \
           fclose(fd); \
@@ -453,7 +453,7 @@ festival_accept_any_response(FT_Info *info)
         fd = fdopen(dup(info->server_fd),"wb"); \
         if (fd != NULL){ \
           str = g_strdup_printf(format"\n", args); \
-          fprintf(fd, str); \
+          fputs(str, fd); \
           DBG("-> Festival: |%s|", str); \
           free(str); \
           fclose(fd); \
@@ -546,7 +546,7 @@ festival_speak_command(FT_Info *info, char *command, const 
char *text, int symbo
       str = g_strdup_printf("(%s \"", command);
     else
       str = g_strdup_printf("(%s '", command);
-    fprintf(fd, str);
+    fputs(str, fd);
     /* Copy text over to server, escaping any quotes */
     for (p=text; p && (*p != '\0'); p++)
     {
diff --git a/src/modules/flite.c b/src/modules/flite.c
index 4ddf663..a963821 100644
--- a/src/modules/flite.c
+++ b/src/modules/flite.c
@@ -366,6 +366,8 @@ _flite_speak(void* nothing)
                        case SPD_AUDIO_BE:
                            ret = spd_audio_play(module_audio_id, track, 
SPD_AUDIO_BE);
                            break;
+                        default:
+                            FATAL("unknown audio format");
                    }
                    if (ret < 0) DBG("ERROR: spd_audio failed to play the 
track");
                    if (flite_stop){
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index 99167e6..bc289dd 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -812,11 +812,11 @@ module_child_dp_write(TModuleDoublePipe dpipe, const char 
*msg, size_t bytes)
 int
 module_parent_dp_write(TModuleDoublePipe dpipe, const char *msg, size_t bytes)
 {
-    int ret;
+    ssize_t ret;
     assert(msg != NULL);
-    DBG("going to write %ld bytes", bytes);
+    DBG("going to write %lu bytes", (long unsigned) bytes);
     ret = write(dpipe.pc[1], msg, bytes);      
-    DBG("written %d bytes", ret);
+    DBG("written %ld bytes", (long) ret);
     return ret;
 }
 
@@ -996,7 +996,7 @@ module_send_asynchronous(char *text)
 {
     pthread_mutex_lock(&module_stdout_mutex);
     DBG("Printing reply: %s", text);
-    fprintf(stdout, text);
+    fputs(text, stdout);
     fflush(stdout);
     DBG("Printed");
     pthread_mutex_unlock(&module_stdout_mutex);
diff --git a/src/server/options.c b/src/server/options.c
index 1502dbc..4e1bd60 100644
--- a/src/server/options.c
+++ b/src/server/options.c
@@ -30,6 +30,25 @@
 
 #include "options.h"
 
+static const struct option spd_long_options_[] = {
+    {"run-daemon", 0, 0, 'd'},
+    {"run-single", 0, 0, 's'},
+    {"spawn", 0, 0, 'a'},
+    {"log-level", 1, 0, 'l'},
+    {"communication-method", 1, 0, 'c'},
+    {"socket-path", 1, 0, 'S'},
+    {"port", 1, 0, 'p'},
+    {"pid-file", 1, 0, 'P'},
+    {"config-file", 1, 0, 'C'},
+    {"version", 0, 0, 'v'},
+    {"debug", 0, 0, 'D'},
+    {"help", 0, 0, 'h'},
+    {0, 0, 0, 0}
+};
+const struct option *const spd_long_options = spd_long_options_;
+
+const char *const spd_short_options = "dsal:c:S:p:P:C:vDh";
+
 void
 options_print_help(char *argv[])
 {
diff --git a/src/server/options.h b/src/server/options.h
index bcc10c4..c08a63e 100644
--- a/src/server/options.h
+++ b/src/server/options.h
@@ -23,23 +23,9 @@
 
 #include <getopt.h>
 
-static struct option spd_long_options[] = {
-    {"run-daemon", 0, 0, 'd'},
-    {"run-single", 0, 0, 's'},
-    {"spawn", 0, 0, 'a'},
-    {"log-level", 1, 0, 'l'},
-    {"communication-method", 1, 0, 'c'},
-    {"socket-path", 1, 0, 'S'},
-    {"port", 1, 0, 'p'},
-    {"pid-file", 1, 0, 'P'},
-    {"config-file", 1, 0, 'C'},
-    {"version", 0, 0, 'v'},
-    {"debug", 0, 0, 'D'},
-    {"help", 0, 0, 'h'},
-    {0, 0, 0, 0}
-};
+const struct option *const spd_long_options;
 
-static char* spd_short_options = "dsal:c:S:p:P:C:vDh";
+const char *const spd_short_options;
 
 void options_print_help(char *argv[]);
 void options_print_version(void);
diff --git a/src/server/parse.c b/src/server/parse.c
index eae7d4e..196e7ca 100644
--- a/src/server/parse.c
+++ b/src/server/parse.c
@@ -384,7 +384,8 @@ char*
 parse_set(const char *buf, const int bytes, const int fd, const TSpeechDSock 
*speechd_socket)
 {
     int who;                    /* 0 - self, 1 - uid specified, 2 - all */
-    int uid;                    /* uid of the client (only if who == 1) */
+    int uid = -1;               /* uid of the client (only if who == 1) */
+                                /* uid = -1 avoids gcc warning */
     int ret = -1; // =-1 has no effect but avoids gcc warning  
     char *set_sub;
     char *who_s;
diff --git a/src/server/sem_functions.c b/src/server/sem_functions.c
index d5debb4..6479eb5 100644
--- a/src/server/sem_functions.c
+++ b/src/server/sem_functions.c
@@ -30,5 +30,7 @@ speaking_semaphore_post(void)
 {
     char buf[1];
     buf[0] = 42;
-    write(speaking_pipe[1], buf, 1);
+    const ssize_t wr_bytes = TEMP_FAILURE_RETRY(write(speaking_pipe[1], buf, 
1));
+    if (wr_bytes != 1)
+        FATAL("write to polled fd: could not write 1 byte");
 }
diff --git a/src/server/speaking.c b/src/server/speaking.c
index 20d0977..1e6fff6 100644
--- a/src/server/speaking.c
+++ b/src/server/speaking.c
@@ -22,8 +22,10 @@
  * $Id: speaking.c,v 1.56 2008-10-15 18:06:48 hanke Exp $
  */
 
+#define _GNU_SOURCE
 #include <glib.h>
 #include <poll.h>
+#include <unistd.h>
 #include "speechd.h"
 #include "server.h"
 #include "index_marking.h"
@@ -79,9 +81,11 @@ speak(void* data)
            poll_fds[0].revents, poll_fds[1].revents);
        if( (revents = poll_fds[0].revents) ){
            if (revents & POLLIN){
-               char buf[100];
+               char buf[1];
                MSG(5, "wait_for_poll: activity in Speech Dispatcher");
-               read(poll_fds[0].fd, buf, 1);
+               const ssize_t rd_bytes = 
TEMP_FAILURE_RETRY(read(poll_fds[0].fd, buf, 1));
+                if (rd_bytes != 1)
+                    FATAL("read from polled fd: could not read 1 byte");
            }       
        }
        if (poll_count > 1){
diff --git a/src/tests/run_test.c b/src/tests/run_test.c
index c516f2a..f2e87fa 100644
--- a/src/tests/run_test.c
+++ b/src/tests/run_test.c
@@ -23,6 +23,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -99,7 +100,7 @@ wait_for(int fd, char* event)
         }
     }
     free(reply);
-    printf("       Continuing.\n", reply);
+    printf("       Continuing.\n");
     fflush(NULL);
 }
 
@@ -297,7 +298,9 @@ main(int argc, char* argv[])
         }
         
         if(line[0] == '*'){
-            system("clear");
+            int ret = system("clear");
+            if (ret == -1)
+                FATAL("Could not execute subprocess");
             for (i=0; i<=indent - 1; i++){
                 printf("\n");
             }                          
-- 
1.7.2.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]