hi all ,

i hope you can help me with the following :
in types.h :

/* Structure of input buffer for each switch */
typedef struct InputBuffer *InputBufferPtr;
typedef struct {
	struct List **fifo; 	/* Input fifos: one per output. */
  
	void *traffic; 			/* Placeholder for traffic stats for this input */
	int (*trafficModel)();  /* Traffic generating function */
	Stat bufferStats;		/* Aggregate occupancy statistics for this input. */
	struct Histogram bufferHistogram;	/* Agg occupancy statistics for this input. */
	int  numOverflows;		/* Total number of cells dropped at this input. */
  
	struct List **mcastFifo;		/* Multicast queue for this input. */
  
	// #ifdef use_gbvoq
	struct List *inputPriorityList ;	/* IPL queue for this input. */
	// #endif

} InputBuffer;

in create.c :

#ifdef use_gbvoq
		inputBuffer->inputPriorityList = (struct List *)malloc( sizeof(struct List)) ;
		if( inputBuffer->inputPriorityList == NULL )	FatalError("createInputBuffer(): Malloc failed.\n") ;
		assert( inputBuffer->inputPriorityList != NULL ) ;
		inputBuffer->inputPriorityList = createList(inputBufferName) ;
	#endif

but, i am going to make use of the linked list inputPriorityList in defaultInputAction.c :

assert( aSwitch->inputBuffer[input]->inputPriorityList != NULL ) ;
/* Add cell to IPL. */
				if( aSwitch->inputBuffer[input]->fifo[pri]->number == 1 ) /* Cell has already been added to a VOQ. = empty VOQ. */
					addElementAtHead(aSwitch->inputBuffer[input]->inputPriorityList, anElement) ;

the assert fails and if i remove it, i get a bus error in
addElementAtHead fuction

Basically, the aSwitch->inputBuffer[input]->inputPriorityList is NULL and i do NOT know WHY ...

i would be thankful if you help me overcome this problem
thanx

Assuming the input buffer you are testing is the same input buffer that was allocated, the only thing that stands out in the code you posted is this:

inputBuffer->inputPriorityList = createList(inputBufferName) ;

createList() might be returning a null pointer in some cases.

but if i write (in create.c)

inputBuffer->inputPriorityList = createList(inputBufferName) ;
		assert( inputBuffer->inputPriorityList != NULL ) ;

the assert doesn t fail

/*****************************************************************/
/***************************  createList() ***********************/
/*****************************************************************/
struct List * createList(char *name)
{
  struct List *aList;
  int type;

#ifdef FREELIST 
  aList = (struct List *) ringMalloc(&freeListList, sizeof(struct List));
#else
  aList = (struct List *) malloc( sizeof(struct List) );
#endif
  memset(aList, 0, sizeof(struct List));
  if( !aList )
    {
      perror("createList:");
      exit(1);
    }

  aList->name = (char *) malloc(sizeof(char)*(strlen(name)+1));
  strcpy(aList->name,name);
  aList->number = 0;
  aList->maxNumber = -1; /* No limit set. */
  aList->head = aList->tail = NULL;
return( aList );
}

an inputPrioriyList is associated with every inputBuffer struct (types.h)
and via the index inputBuffer[input] reasonably i address to the inputBuffer that i am interested in

thank you for your interest

Edited 7 Years Ago by OneDreamCloser: n/a

Then it is getting set to null somewhere. Maybe you have a buffer overflow somewhere, or some other memory corruption that is blowing up at that point. Memory errors are the hardest to debug, so you might be stuck with stepping through your code and watching that pointer until you find the cause.

This article has been dead for over six months. Start a new discussion instead.