From f9b7a98b18c8c1dc20744e86352f0447a2cf2e77 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 17 Jun 2006 17:01:42 +0000 Subject: [BZ #2766] 2006-06-14 Jakub Jelinek [BZ #2766] * misc/insremque.c (insque): Handle prev == NULL. * misc/Makefile (tests): Add tst-insremque. * misc/tst-insremque.c: New test. --- misc/insremque.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'misc/insremque.c') 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. */ -- cgit 1.4.1