about summary refs log tree commit diff
path: root/misc/insremque.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-06-17 17:01:42 +0000
committerUlrich Drepper <drepper@redhat.com>2006-06-17 17:01:42 +0000
commitf9b7a98b18c8c1dc20744e86352f0447a2cf2e77 (patch)
treef351c0ff36f4fab4efb9bc6bafa08cb69133c636 /misc/insremque.c
parentac55a25bfc4c4e32d7e8b4acad140767c577dbf0 (diff)
downloadglibc-f9b7a98b18c8c1dc20744e86352f0447a2cf2e77.tar.gz
glibc-f9b7a98b18c8c1dc20744e86352f0447a2cf2e77.tar.xz
glibc-f9b7a98b18c8c1dc20744e86352f0447a2cf2e77.zip
[BZ #2766]
2006-06-14  Jakub Jelinek  <jakub@redhat.com>
	[BZ #2766]
	* misc/insremque.c (insque): Handle prev == NULL.
	* misc/Makefile (tests): Add tst-insremque.
	* misc/tst-insremque.c: New test.
Diffstat (limited to 'misc/insremque.c')
-rw-r--r--misc/insremque.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/misc/insremque.c b/misc/insremque.c
index e366ac8063..7f086cd392 100644
--- a/misc/insremque.c
+++ b/misc/insremque.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1995, 1996, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -24,12 +24,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;
+    }
 }
 
 /* Unlink ELEM from the doubly-linked list that it is in.  */