Subject: bug#9064: [PATCH] coreutils-8.12 compiler warning

From: "Voelker, Bernhard" <[email-masked]>
Date: Thu, 14 Jul 2011 09:38:21 +0200

Pádraig Brady wrote:

>On 13/07/11 14:11, Eric Blake wrote:
>> On 07/13/2011 03:05 AM, Pádraig Brady wrote:
>>> On 13/07/11 08:55, Joachim Schmitz wrote:
>>>> I found this in mktemp.c, line344 (well, my compiler found it for me and
>>>> warned about 'possible use of "=" where "==" was intended'):
>>>>
>>>>       if (!dry_run && (stdout_closed = true) && close_stream (stdout) != 0)
>>>>
>>>> Not sure whether this is bug or feature ;-)
>>>
>>> Well it's a feature.
>>> We could reorganize but it would add a few more lines.
>> 
>> Does this avoid the warning?
>> 
>> if (!dry_run && ((stdout_closed = true), close_stream (stdout) != 0))
>> 
>> That is, using the comma operator rather than an always-true conditional
>> since we always want the assignment to occur at that part of the expression?
>
> +1 for this version

As Joachim wrote (off-ML) that his compiler didn't complain about
the other, similar place in src/stat.c, the following patch doesn't
touch that one (as my first patch did: http://debbugs.gnu.org/9064#19).

>From 2fc0d6282d304a76241eb66f0f0627fb189e3ec9 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email-masked]>
Date: Thu, 14 Jul 2011 09:19:55 +0200
Subject: [PATCH] maint: fix warning 'possible use of "=" where "==" was
 intended'

* src/mktemp.c: maint: avoid warning by using the comma operator
rather than an always-true conditional (as suggested by Eric Blake).
Reported by Joachim Schmitz in http://debbugs.gnu.org/9064.
---
 src/mktemp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/mktemp.c b/src/mktemp.c
index 2fe22b7..e592176 100644
--- a/src/mktemp.c
+++ b/src/mktemp.c
@@ -344,7 +344,7 @@ main (int argc, char **argv)
       puts (dest_name);
       /* If we created a file, but then failed to output the file
          name, we should clean up the mess before failing.  */
-      if (!dry_run && (stdout_closed = true) && close_stream (stdout) != 0)
+      if (!dry_run && ((stdout_closed = true), close_stream (stdout) != 0))
         {
           int saved_errno = errno;
           remove (dest_name);
-- 
1.7.5.1

Have a nice day,
Berny