public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: dwz@sourceware.org, jakub@redhat.com, mark@klomp.org
Subject: [committed] Fix incorrect res arg for wait_child_exit
Date: Mon, 29 Mar 2021 08:36:38 +0200	[thread overview]
Message-ID: <20210329063637.GA3436@delia> (raw)

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);
 	    }

                 reply	other threads:[~2021-03-29  6:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210329063637.GA3436@delia \
    --to=tdevries@suse.de \
    --cc=dwz@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).