Skip to contentSkip to conversation

Don't compare a non-existing function with NULL

PATCH Applied Daniel Mierswa 3 participants 4 messages Aug 17, 2009 – Aug 18, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Don't compare a non-existing function with NULL

Obviously someone forgot something here or didn't use -ansi. Either way, index is nowhere declared so I assume the current behaviour is to check against the index() function coming from somewhere in the POSIX headers. The comparison doesn't make sense then.

---
 libudev/libudev-queue-private.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
libudev/libudev-queue-private.c +0 -2
index 0427b65..c8e0150 100644
@@ -158,8 +158,6 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
 		return NULL;
 	}
 	devpaths = calloc(1, sizeof(struct queue_devpaths) + (range + 1) * sizeof(long));
-	if (index == NULL)
-		return NULL;
 	devpaths->devpaths_size = range + 1;
 
 	/* read all records and populate the table */
#1 lore raw
Quoted 2 lines · Daniel Mierswa

Obviously someone forgot something here or didn't use -ansi.

Guilty as charged.

Quoted 4 lines

Either way,
index is nowhere declared so I assume the current behaviour is to check against the index() function coming from somewhere in the POSIX headers. The comparison doesn't make sense then.

devpaths = calloc(1, sizeof(struct queue_devpaths) + (range + 1) *
sizeof(long));
- if (index = NULL)
- return NULL;
devpaths->devpaths_size = range + 1;

nak. The intention would have been to catch an "out of memory error" when allocating devpaths. It should make sense if you replace "index" with "devpaths" on that line instead,

Thanks for spotting this
Alan

#2 lore raw
In reply to Daniel Mierswa
Quoted 3 lines · Alan Jenkins

nak. The intention would have been to catch an "out of memory error" when allocating devpaths. It should make sense if you replace "index" with "devpaths" on that line instead,

done

New patch attached.

From 52311df17535588c767e64be55116c8f5f14c473 Mon Sep 17 00:00:00 2001
From: Daniel Mierswa <[email protected]>
Date: Mon, 17 Aug 2009 14:59:26 +0200
Subject: [PATCH] Don't compare a non-existing function with NULL

Obviously someone forgot something here or didn't use -ansi. Either way, index is nowhere declared so I assume the current behaviour is to check against the index() function coming from somewhere in the POSIX headers. The comparison doesn't make sense then.

---
 libudev/libudev-queue-private.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
libudev/libudev-queue-private.c +1 -1
index 0427b65..4dea4ad 100644
@@ -158,7 +158,7 @@ static struct queue_devpaths *build_index(struct udev_queue_export *udev_queue_e
 		return NULL;
 	}
 	devpaths = calloc(1, sizeof(struct queue_devpaths) + (range + 1) * sizeof(long));
-	if (index == NULL)
+	if (devpaths == NULL)
 		return NULL;
 	devpaths->devpaths_size = range + 1;
 
Signature · 1 line
1.6.4
Applied
#3 lore raw
In reply to Daniel Mierswa
Quoted 7 lines · Daniel Mierswa
Quoted 3 lines · Alan Jenkins

nak.  The intention would have been to catch an "out of memory error" when allocating devpaths.  It should make sense if you replace "index" with "devpaths" on that line instead,

done

New patch attached.

Applied.

Thanks,
Kay