public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Fix incorrect res arg for wait_child_exit
@ 2021-03-29  6:36 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2021-03-29  6:36 UTC (permalink / raw)
  To: dwz, jakub, mark

Hi,

In dwz_files_1 we have:
...
         file = files[i];
         struct file_result *res = &resa[i];

         if (nr_forks == max_forks)
           {
             int thisret = wait_child_exit (-1, pids, i, res);
...

The -1 pid argument to wait_child_exit means that any child status will be
returned, while the res argument passes the result array element for
the file we want to start processing, which is incorrect.

Fix this by passing the result array instead, and letting wait_child_exit
figure out which element to use.

Committed to trunk.

Thanks,
- Tom

Fix incorrect res arg for wait_child_exit

2021-03-29  Tom de Vries  <tdevries@suse.de>

	* dwz.c (wait_child_exit): Find appropriate element in result array.
	(dwz_files_1): Use resa when using pid -1.

---
 dwz.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/dwz.c b/dwz.c
index 0ba04c5..377e1be 100644
--- a/dwz.c
+++ b/dwz.c
@@ -16446,7 +16446,7 @@ decode_child_exit_status (int state, struct file_result *res)
 /* Wait on child exit with PID, update PIDS and RES.  */
 static int
 wait_child_exit (pid_t pid, pid_t *pids, int nr_pids,
-		 struct file_result *res)
+		 struct file_result *resa)
 {
   int state;
   pid_t got_pid = waitpid (pid, &state, 0);
@@ -16460,7 +16460,7 @@ wait_child_exit (pid_t pid, pid_t *pids, int nr_pids,
       }
   assert (i < nr_pids);
 
-  return decode_child_exit_status (state, res);
+  return decode_child_exit_status (state, &resa[i]);
 }
 
 /* Wait on exit of chilren in PIDS, update RESA.  */
@@ -16541,12 +16541,10 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	{
 	  int i = workset[j];
 	  int thisret;
-	  file = files[i];
-	  struct file_result *res = &resa[i];
 
 	  if (nr_forks == max_forks)
 	    {
-	      int thisret = wait_child_exit (-1, pids, i, res);
+	      int thisret = wait_child_exit (-1, pids, i, resa);
 	      if (thisret == 1)
 		ret = 1;
 	      nr_forks--;
@@ -16556,6 +16554,8 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	  assert (fork_res != -1);
 	  if (fork_res == 0)
 	    {
+	      file = files[i];
+	      struct file_result *res = &resa[i];
 	      thisret = dwz_with_low_mem (file, NULL, res);
 	      return encode_child_exit_status (thisret, res);
 	    }
@@ -16644,13 +16644,10 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
       for (j = 0; j < workset_size; j++)
 	{
 	  int i = workset[j];
-	  file = files[i];
-	  struct file_result *res = &resa[i];
-	  multifile_mode = MULTIFILE_MODE_FI;
 
 	  if (nr_forks == max_forks)
 	    {
-	      int thisret = wait_child_exit (-1, pids, i, res);
+	      int thisret = wait_child_exit (-1, pids, i, resa);
 	      if (thisret == 1)
 		ret = 1;
 	      nr_forks--;
@@ -16660,6 +16657,9 @@ dwz_files_1 (int nr_files, char *files[], bool hardlink,
 	  assert (fork_res != -1);
 	  if (fork_res == 0)
 	    {
+	      file = files[i];
+	      struct file_result *res = &resa[i];
+	      multifile_mode = MULTIFILE_MODE_FI;
 	      int thisret = dwz (file, NULL, res);
 	      return encode_child_exit_status (thisret, res);
 	    }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-29  6:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29  6:36 [committed] Fix incorrect res arg for wait_child_exit Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).