[v11,14/16] log: use standard ternary operator instead of GCC extension

Message ID 1691781658-32520-15-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series msvc integration changes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff Aug. 11, 2023, 7:20 p.m. UTC
  Use standard ternary operator instead of gcc extension. There is
no concern of side-effects for this evaluation so allow the code
to be portable.

While here update the condition to compare default_log_stream
directly against NULL.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/log/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Morten Brørup Sept. 25, 2023, 6:24 a.m. UTC | #1
> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> Sent: Friday, 11 August 2023 21.21
> 
> Use standard ternary operator instead of gcc extension. There is
> no concern of side-effects for this evaluation so allow the code
> to be portable.
> 
> While here update the condition to compare default_log_stream
> directly against NULL.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  lib/log/log.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/log/log.c b/lib/log/log.c
> index 52c771f..b80725a 100644
> --- a/lib/log/log.c
> +++ b/lib/log/log.c
> @@ -93,7 +93,7 @@ struct log_cur_msg {
>  		 * of stderr, even if the application closes and
>  		 * reopens it.
>  		 */
> -		return default_log_stream ? : stderr;

I didn't know this GCC extension.

Someone please consider disallowing this in checkpatches.


> +		return default_log_stream != NULL ? default_log_stream : stderr;
>  	}
>  	return f;
>  }
> --
> 1.8.3.1

Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
  
Stephen Hemminger Sept. 25, 2023, 3:09 p.m. UTC | #2
On Mon, 25 Sep 2023 08:24:58 +0200
Morten Brørup <mb@smartsharesystems.com> wrote:

> I didn't know this GCC extension.
> 
> Someone please consider disallowing this in checkpatches.

We don't need to make checkpatch more complex.
When MSVC is in build system, it will catch it
  

Patch

diff --git a/lib/log/log.c b/lib/log/log.c
index 52c771f..b80725a 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -93,7 +93,7 @@  struct log_cur_msg {
 		 * of stderr, even if the application closes and
 		 * reopens it.
 		 */
-		return default_log_stream ? : stderr;
+		return default_log_stream != NULL ? default_log_stream : stderr;
 	}
 	return f;
 }