Skip to contentSkip to conversation

run-command.c: Fix unused variables warning with gcc 4.6

PATCH In review Michael Schubert 4 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 run-command.c: Fix unused variables warning with gcc 4.6

As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Remove all unused variables to prevent those warnings.

---
 run-command.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
run-command.c +4 -6
index f91e446..6e0be54 100644
@@ -67,21 +67,19 @@ static int child_notifier = -1;
 
 static void notify_parent(void)
 {
-	ssize_t unused;
-	unused = write(child_notifier, "", 1);
+	write(child_notifier, "", 1);
 }
 
 static NORETURN void die_child(const char *err, va_list params)
 {
 	char msg[4096];
-	ssize_t unused;
 	int len = vsnprintf(msg, sizeof(msg), err, params);
 	if (len > sizeof(msg))
 		len = sizeof(msg);
 
-	unused = write(child_err, "fatal: ", 7);
-	unused = write(child_err, msg, len);
-	unused = write(child_err, "\n", 1);
+	write(child_err, "fatal: ", 7);
+	write(child_err, msg, len);
+	write(child_err, "\n", 1);
 	exit(128);
 }
 #endif
Signature · 1 line
1.7.4.4
#1 lore raw

Hi Michael,

Quoted 2 lines · Michael Schubert

As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Remove all unused variables to prevent those warnings.

As the other Michael mentioned, this patch replaces one warning with another. You might like a111eb7 (run-command: handle short writes and EINTR in die_child, 2011-04-20, aka jn/run-command-error-failure in "pu"), which eliminates both.

Andreas, a patch on top to short-circuit away the later writes on error doesn't sound bad to me if you'd like, though it seems like a bit of an edge case.

Thanks, all.
Jonathan

#2 lore raw
In reply to Michael Schubert

Michael Schubert venit, vidit, dixit 26.04.2011 14:28:

Quoted 28 lines

As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Remove all unused variables to prevent those warnings.

---
 run-command.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
run-command.c +1 -3
index f91e446..6e0be54 100644
@@ -67,21 +67,19 @@ static int child_notifier = -1;
 
 static void notify_parent(void)
 {
-	ssize_t unused;
-	unused = write(child_notifier, "", 1);
+	write(child_notifier, "", 1);
 }
 
 static NORETURN void die_child(const char *err, va_list params)
 {
 	char msg[4096];
-	ssize_t unused;
 	int len = vsnprintf(msg, sizeof(msg), err, params);
 	if (len > sizeof(msg))
 		len = sizeof(msg);

run-command.c static int child_notifier = -1; · line 85

Quoted 10 lines
run-command.c +3 -3
 
-	unused = write(child_err, "fatal: ", 7);
-	unused = write(child_err, msg, len);
-	unused = write(child_err, "\n", 1);
+	write(child_err, "fatal: ", 7);
+	write(child_err, msg, len);
+	write(child_err, "\n", 1);
 	exit(128);
 }
 #endif

git log -S"unused" origin/master run-command.c

shows that these dummies were introduced for a reason. How do you invalidate that?

Michael

#3 lore raw
Quoted 42 lines · Michael J Gruber

Michael Schubert venit, vidit, dixit 26.04.2011 14:28:

Quoted 28 lines

As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Remove all unused variables to prevent those warnings.

---
 run-command.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
run-command.c +1 -3
index f91e446..6e0be54 100644
@@ -67,21 +67,19 @@ static int child_notifier = -1;
 
 static void notify_parent(void)
 {
-	ssize_t unused;
-	unused = write(child_notifier, "", 1);
+	write(child_notifier, "", 1);
 }
 
 static NORETURN void die_child(const char *err, va_list params)
 {
 	char msg[4096];
-	ssize_t unused;
 	int len = vsnprintf(msg, sizeof(msg), err, params);
 	if (len > sizeof(msg))
 		len = sizeof(msg);

run-command.c static int child_notifier = -1; · line 85

Quoted 10 lines
run-command.c +3 -3
 
-	unused = write(child_err, "fatal: ", 7);
-	unused = write(child_err, msg, len);
-	unused = write(child_err, "\n", 1);
+	write(child_err, "fatal: ", 7);
+	write(child_err, msg, len);
+	write(child_err, "\n", 1);
 	exit(128);
 }
 #endif

git log -S"unused" origin/master run-command.c

Quoted 2 lines

shows that these dummies were introduced for a reason. How do you invalidate that?

Sorry, just missed that.

#4 lore raw
Quoted 43 lines · Michael Schubert
Quoted 42 lines · Michael J Gruber

Michael Schubert venit, vidit, dixit 26.04.2011 14:28:

Quoted 28 lines

As of gcc 4.6 -Wall includes -Wunused-but-set-variable. Remove all unused variables to prevent those warnings.

---
  run-command.c |   10 ++++------
  1 files changed, 4 insertions(+), 6 deletions(-)
run-command.c +1 -3
index f91e446..6e0be54 100644
@@ -67,21 +67,19 @@ static int child_notifier = -1;
 
  static void notify_parent(void)
  {
-	ssize_t unused;
-	unused = write(child_notifier, "", 1);
+	write(child_notifier, "", 1);
  }
 
  static NORETURN void die_child(const char *err, va_list params)
  {
  	char msg[4096];
-	ssize_t unused;
  	int len = vsnprintf(msg, sizeof(msg), err, params);
  	if (len>  sizeof(msg))
  		len = sizeof(msg);

run-command.c static int child_notifier = -1; · line 85

Quoted 10 lines
run-command.c +3 -3
 
-	unused = write(child_err, "fatal: ", 7);
-	unused = write(child_err, msg, len);
-	unused = write(child_err, "\n", 1);
+	write(child_err, "fatal: ", 7);
+	write(child_err, msg, len);
+	write(child_err, "\n", 1);
  	exit(128);
  }
  #endif

git log -S"unused" origin/master run-command.c

Quoted 5 lines
Quoted 2 lines

shows that these dummies were introduced for a reason. How do you invalidate that?

Sorry, just missed that.

A better solution than reverting the prettifying commit ebec842773932e6f853acac70c80f84209b5f83e would be to rework it to use logical AND instead of logical OR, as the AND-chain won't short-circuit the statement chain early and prevent output from being printed when write() returns non-zero. When it *does* return zero, it's likely due to problems on the receiving ends, making further writing totally pointless anyway.

Signature · 7 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.