]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
coverity: various fixes
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 3 Sep 2023 06:28:26 +0000 (08:28 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 3 Sep 2023 06:29:23 +0000 (08:29 +0200)
Null check, uninitialized variable and several print format uses of size_t.
clang-tidy also complains about most of them.

coregrind/m_debuginfo/debuginfo.c
coregrind/m_debuginfo/readelf.c
coregrind/vgdb.c

index 0c4eb99c0d8cd27151bcb237f41015a12964dbc9..4f6ffd48ae79845d5e9228f6a040ba8ec825bc6a 100644 (file)
@@ -2828,7 +2828,7 @@ const HChar* VG_(describe_IP)(DiEpoch ep, Addr eip, const InlIPCursor *iipc)
                      );
       know_dirinfo = buf_dirname[0] != '\0';
    } else {
-      const DiInlLoc *cur_inl = iipc && iipc->cur_inltab >= 0
+      const DiInlLoc *cur_inl = iipc && iipc->di && iipc->cur_inltab >= 0
          ? & iipc->di->inltab[iipc->cur_inltab]
          : NULL;
       vg_assert (cur_inl);
index ef9a722ad9b241ae1d146234f51a2a33ec463bd0..13efc46b842b472b4e9444b98bc9e8d8ce4a3ea3 100644 (file)
@@ -2933,7 +2933,8 @@ Bool ML_(read_elf_object) ( struct _DebugInfo* di )
       /* TOPLEVEL */
       /* Read .eh_frame and .debug_frame (call-frame-info) if any.  Do
          the .eh_frame section(s) first. */
-      vg_assert(di->n_ehframe >= 0 && di->n_ehframe <= N_EHFRAME_SECTS);
+      /* i->n_ehframe is unsigned and cannot be negative */
+      vg_assert(di->n_ehframe <= N_EHFRAME_SECTS);
       for (i = 0; i < di->n_ehframe; i++) {
          /* see Comment_on_EH_FRAME_MULTIPLE_INSTANCES above for why
             this next assertion should hold. */
index 9e21a00d66626dd31258b0269fa112a654d032b3..8e030e27b1b41644da0d8f068cdf9e3dca8a5866 100644 (file)
@@ -1035,8 +1035,11 @@ send_packet_start:
 // or -1 if no packet could be read.
 static int receive_packet(char *buf, int noackmode)
 {
-   int bufcnt = 0, ret;
-   char c, c1, c2;
+   int bufcnt = 0;
+   int ret;
+   char c;
+   char c1 = '\0';
+   char c2;
    unsigned char csum = 0;
 
    // Look for first '$' (start of packet) or error.
@@ -1428,12 +1431,12 @@ void do_multi_mode(int check_trials, int in_port)
 
           // Count the lenghts of each substring, init to -1 to compensate for
           // each substring starting with a delim char.
-          for (int i = 0; i < count; i++)
+          for (size_t i = 0; i < count; i++)
              len[i] = -1;
           count_len(';', buf, len);
           if (next_str) {
              DEBUG(1, "vRun: next_str %s\n", next_str);
-             for (int i = 0; i < count; i++) {
+             for (size_t i = 0; i < count; i++) {
                 /* Handle the case when the arguments
                  * was specified to gdb's run command
                  * but no remote exec-file was set,
@@ -1449,16 +1452,16 @@ void do_multi_mode(int check_trials, int in_port)
                    if (i < count - 1)
                       next_str = next_delim_string(next_str, *delim);
                 }
-                DEBUG(1, "vRun decoded: %s, next_str %s, len[%d] %d\n",
+                DEBUG(1, "vRun decoded: %s, next_str %s, len[%zu] %zu\n",
                       decoded_string[i], next_str, i, len[i]);
              }
 
              /* If we didn't get any arguments or the filename is an empty
                 string, valgrind won't know which program to run.  */
-             DEBUG (1, "count: %d, len[0]: %d\n", count, len[0]);
+             DEBUG (1, "count: %zu, len[0]: %zu\n", count, len[0]);
              if (! count || len[0] == 0) {
                 free(len);
-                for (int i = 0; i < count; i++)
+                for (size_t i = 0; i < count; i++)
                    free (decoded_string[i]);
                 free (decoded_string);
                 send_packet ("E01", noackmode);
@@ -1469,7 +1472,7 @@ void do_multi_mode(int check_trials, int in_port)
                 launch valgrind with the correct arguments... We then use the
                 valgrind pid to start relaying packets.  */
              pid_t valgrind_pid = -1;
-             int res = fork_and_exec_valgrind (count,
+             int res = fork_and_exec_valgrind ((int)count,
                                                decoded_string,
                                                working_dir,
                                                in_port,
@@ -1706,7 +1709,7 @@ void gdb_relay(int pid, int send_noack_mode, char *q_buf)
                   buflen = getpkt(buf, from_pid, to_pid);
                   if (buflen != 2 || strcmp(buf, "OK") != 0) {
                      if (buflen != 2)
-                        ERROR(0, "no ack mode: unexpected buflen %d, buf %s\n",
+                        ERROR(0, "no ack mode: unexpected buflen %zu, buf %s\n",
                               buflen, buf);
                      else
                         ERROR(0, "no ack mode: unexpected packet %s\n", buf);
@@ -1729,7 +1732,7 @@ void gdb_relay(int pid, int send_noack_mode, char *q_buf)
                   if (buflen > 0) {
                      waiting_for_qsupported = False;
                   } else {
-                     ERROR(0, "Unexpected getpkt for qSupported reply: %d\n",
+                     ERROR(0, "Unexpected getpkt for qSupported reply: %zu\n",
                            buflen);
                   }
                } else if (!read_from_pid_write_to_gdb(from_pid))