delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/16/05:17:29

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: insque() flaw?
Date: Thu, 16 Oct 1997 09:11:03 +0200
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 49
Message-ID: <3445BE07.EFCFA3C1@LSTM.Ruhr-UNI-Bochum.De>
NNTP-Posting-Host: c64.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This may be bug in insque() or just a misundertanding the
concept from my point of view. 
Insque() is meant to build double linked lists, so I started
with something like this:

stuct qelem root, *data;
/*
** Empty List
*/
 root.q_forw = root.q_back = NULL;
/*
** Insert a node
*/
 data = malloc(sizeof(*data)); 
 insque(data, &root);

and ended up with a SIGSEGV. The reason is quite simple.
insque() wants to set 
  root->q_forw->q_back = q
which is wrong in this case, because root->q_forw == NULL.

The reason for using NULL was just to have an idea when 
the list end is reached, which is a quite common idea to my knowledge.

The work-around is using &root as a sentinel for list end and
beginning, but it still annoys me ;-)

I couldn't find a hint in the docs and neither in my UNIX
man pages. But the code runs under AIX, which may or may not
be an indication... 

IBM, OTOH, forgot the definition of qelem...



-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019