[PATCH 20/22] scripts: omap3-usb-loader: fix clang-analyzer false-positive

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Mar 13 00:34:43 PDT 2025


clang-analyzer has a heuristic to determine mismatched allocations.
It flags allocating bufsize of chars and assigned it to a pointer
to uint32, although it's ultimately correct.

Let's silence the warning by using the pointee type instead.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 scripts/omap3-usb-loader.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c
index 38cdbfac939e..192e42689bb2 100644
--- a/scripts/omap3-usb-loader.c
+++ b/scripts/omap3-usb-loader.c
@@ -424,15 +424,18 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state
 
 static int transfer_other_files(libusb_device_handle *handle, struct arg_state *args)
 {
-	uint32_t *buffer = NULL;
-	int bufsize = 128 * sizeof (*buffer);
+	uint32_t *buffer;
+	int bufsize;
 	int numfailures = 0;	/* build in some reliablity */
 	int maxfailures = 3;
 	int transLen = 0;
 	int curfile = 1;	/* skip the first file */
 	size_t len;
 
-	buffer = calloc(bufsize, sizeof(unsigned char));
+	buffer = calloc(128, sizeof(*buffer));
+	if (!buffer)
+		goto fail;
+	bufsize = 128 * sizeof (*buffer);
 
 	/* handle the state machine for the X-Loader */
 	while (curfile < args->numfiles) {
-- 
2.39.5




More information about the barebox mailing list