summaryrefslogtreecommitdiff
path: root/libc/misc
diff options
context:
space:
mode:
authorBartosz Golaszewski <bartekgola@gmail.com>2013-06-18 21:02:20 (GMT)
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2013-07-04 09:25:17 (GMT)
commitf9ae36ebf1d8e300c77dfd16b55514ea5a96751f (patch)
treeb4d5a83f7536adfcdd73ea2fedd26dc6377121ca /libc/misc
parent23691332c8458adb469ad78051493ef0db434222 (diff)
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 <bartekgola@gmail.com> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/misc')
-rw-r--r--libc/misc/search/insremque.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/libc/misc/search/insremque.c b/libc/misc/search/insremque.c
index c4a75ab..9939942 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