recordmcount: Fix warning comparing pointer to 0

Message ID 10ee62bd.c2.1844d7ee28a.Coremail.wangkailong@jari.cn
State New
Headers
Series recordmcount: Fix warning comparing pointer to 0 |

Commit Message

KaiLong Wang Nov. 6, 2022, 3:11 p.m. UTC
  Fix the following coccicheck warning:

scripts/recordmcount.c:142:13-14: WARNING comparing pointer to 0.

Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
---
 scripts/recordmcount.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Christophe JAILLET Nov. 6, 2022, 3:56 p.m. UTC | #1
Le 06/11/2022 à 16:11, wangkailong@jari.cn a écrit :
> Fix the following coccicheck warning:
> 
> scripts/recordmcount.c:142:13-14: WARNING comparing pointer to 0.
> 
> Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
> ---
>   scripts/recordmcount.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
> index cce12e1971d8..750f5196608c 100644
> --- a/scripts/recordmcount.c
> +++ b/scripts/recordmcount.c
> @@ -139,7 +139,7 @@ static ssize_t uwrite(void const *const buf, size_t const count)
>   static void * umalloc(size_t size)
>   {
>   	void *const addr = malloc(size);
> -	if (addr == 0) {
> +	if (addr) {

Hi,
this change looks incorrect.

	if (!addr)

maybe?

CJ

>   		fprintf(stderr, "malloc failed: %zu bytes\n", size);
>   		file_append_cleanup();
>   		mmap_cleanup();
  

Patch

diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index cce12e1971d8..750f5196608c 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -139,7 +139,7 @@  static ssize_t uwrite(void const *const buf, size_t const count)
 static void * umalloc(size_t size)
 {
 	void *const addr = malloc(size);
-	if (addr == 0) {
+	if (addr) {
 		fprintf(stderr, "malloc failed: %zu bytes\n", size);
 		file_append_cleanup();
 		mmap_cleanup();