viewing paste Patch gcc warnings | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
Index: src/plugins/console.c
===================================================================
--- src/plugins/console.c   (revision 1)
+++ src/plugins/console.c   (revision 200)
@@ -14,6 +14,7 @@
    #include <string.h>
 #endif
 #include <stdio.h> // stdin, fgets
+#include "../common/showmsg.h" //showerror
 
 #define INPUT_BUFSIZE 4096
 #define INPUT_INVALID 0
@@ -277,8 +278,10 @@
 {
    if( state == INPUT_READY && input_getstate() == INPUT_READING )
    {// send data from the worker to the main process
-       write(buf.data_pipe[PIPE_WRITE], &buf.len, sizeof(buf.len));        
-       write(buf.data_pipe[PIPE_WRITE], &buf.arr, buf.len);
+       if (write(buf.data_pipe[PIPE_WRITE], &buf.len, sizeof(buf.len)) == -1)
+                        ShowError("console.c input_setstate writting1 error");
+       if (write(buf.data_pipe[PIPE_WRITE], &buf.arr, buf.len) == -1)
+                         ShowError("console.c input_setstate writting2 error");
    } else if( state == INPUT_WAITING ){
        if( buf.close_unused_flag == 0 )
        {// close unused pipe sides in the main process
@@ -287,7 +290,8 @@
            buf.close_unused_flag = 1;
        }
        // send the next state
-       write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state));
+       if (write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state)) == -1)
+                     ShowError("console.c input_setstate writting3 error");
    } else if( state == INPUT_READING ){
        if( buf.close_unused_flag == 0 )
        {// close unused pipe sides in the worker process
@@ -297,7 +301,8 @@
        }
    } else if( state == INPUT_CLOSED )
    {// send next state to the worker and close the pipes
-       write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state));
+       if (write(buf.state_pipe[PIPE_WRITE], &state, sizeof(state)) == -1)
+                     ShowError("console.c input_setstate writting4 error");
        close(buf.data_pipe[PIPE_WRITE]);
        close(buf.data_pipe[PIPE_READ]);
        close(buf.state_pipe[PIPE_WRITE]);
@@ -339,8 +344,10 @@
    hasData = ( poll(&fds,1,0) > 0 );
    if( hasData )
    {// read the data from the pipe
-       read(buf.data_pipe[PIPE_READ], &buf.len, sizeof(buf.len));
-       read(buf.data_pipe[PIPE_READ], buf.arr, buf.len);
+       if (read(buf.data_pipe[PIPE_READ], &buf.len, sizeof(buf.len)) == -1);
+                        ShowError("console.c input_hasdata() reading1 error");
+       if (read(buf.data_pipe[PIPE_READ], buf.arr, buf.len) == -1);
+                        ShowError("console.c input_hasdata() reading2 error");
        input_setstate(INPUT_READY);
    }
 
@@ -405,7 +412,8 @@
    {// get input
        input_setstate(INPUT_READING);
        buf.arr[0] = '\0';
-       fgets(buf.arr, INPUT_BUFSIZE, stdin);
+       if (fgets(buf.arr, INPUT_BUFSIZE, stdin) == NULL)
+                    ShowError("console.c WORKER_FUNC_START(getinput) error");
        buf.len = strlen(buf.arr);
        input_setstate(INPUT_READY);
    }
Viewed 1029 times, submitted by lighta.