diff options
Diffstat (limited to 'libc/misc/search/insremque.c')
| -rw-r--r-- | libc/misc/search/insremque.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libc/misc/search/insremque.c b/libc/misc/search/insremque.c index 32edf7a4e..99399427e 100644 --- a/libc/misc/search/insremque.c +++ b/libc/misc/search/insremque.c @@ -13,8 +13,7 @@ You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + see <http://www.gnu.org/licenses/>. */ #include <features.h> #include <stddef.h> @@ -27,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 |
