[PATCH] tools: Change asprintf return code check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,

I found a small error (IMHO) in libgpiod.
The issue is that asprintf may return -1 if it fails to allocate
memory, and if that happens, chip_open_by_number will pass a NULL
pointer to gpiod_chip_open.

I hope this helps.

Thanks,

Catalin.
From e92b71df3c9f8304a91e0dbe0094614df3784941 Mon Sep 17 00:00:00 2001
From: Catalin Petrescu <catalin.petrescu@xxxxxxxxx>
Date: Tue, 6 Sep 2022 19:07:25 -0400
Subject: [PATCH] tools: Change asprintf return code check

Asprintf may return negative numbers in some cases (failure to allocate
memory, for example).
Treat negative values as errors.
---
 tools/tools-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/tools-common.c b/tools/tools-common.c
index 80087ee..8521c93 100644
--- a/tools/tools-common.c
+++ b/tools/tools-common.c
@@ -137,7 +137,7 @@ static struct gpiod_chip *chip_open_by_number(unsigned int num)
 	int ret;
 
 	ret = asprintf(&path, "/dev/gpiochip%u", num);
-	if (!ret)
+	if (ret <= 0)
 		return NULL;
 
 	chip = gpiod_chip_open(path);
-- 
2.34.1


[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux