From f9ae36ebf1d8e300c77dfd16b55514ea5a96751f Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 18 Jun 2013 23:02:20 +0200 Subject: insque: fix segfault on (prev == NULL) Since version 2.5 glibc allows prev to be a NULL pointer in insque, whereas uClibc segfaults in this case. This fixes the issue and makes insque initialize q_forw and q_back with NULLs if prev == NULL. Signed-off-by: Bartosz Golaszewski Signed-off-by: Bernhard Reutner-Fischer --- libc/misc/search/insremque.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'libc/misc') diff --git a/libc/misc/search/insremque.c b/libc/misc/search/insremque.c index c4a75ab89..99399427e 100644 --- a/libc/misc/search/insremque.c +++ b/libc/misc/search/insremque.c @@ -26,12 +26,20 @@ void insque (void *elem, void *prev) { - struct qelem *next = ((struct qelem *) prev)->q_forw; - ((struct qelem *) prev)->q_forw = (struct qelem *) elem; - if (next != NULL) - next->q_back = (struct qelem *) elem; - ((struct qelem *) elem)->q_forw = next; - ((struct qelem *) elem)->q_back = (struct qelem *) prev; + if (prev == NULL) + { + ((struct qelem *) elem)->q_forw = NULL; + ((struct qelem *) elem)->q_back = NULL; + } + else + { + struct qelem *next = ((struct qelem *) prev)->q_forw; + ((struct qelem *) prev)->q_forw = (struct qelem *) elem; + if (next != NULL) + next->q_back = (struct qelem *) elem; + ((struct qelem *) elem)->q_forw = next; + ((struct qelem *) elem)->q_back = (struct qelem *) prev; + } } #endif -- cgit v1.2.3