Server Help

General Questions - Access Violation in a linked list

Versetti - Sat Feb 28, 2004 11:07 pm
Post subject: Access Violation in a linked list
I'm trying to make a addon for my biller and when the biller tries to add data in my linked lists it will say "Unhandled exception in SSGBiller.exe 0xC0000005: Access Violation."

Would anyone know how to fix this if you need to see anything else just ask and I'll show you some of that code you might need to help e out with this problem.
Cyan~Fire - Sat Feb 28, 2004 11:54 pm
Post subject:
Lol show the code. Access violation is probably the most generic C++ error you can ever get.
Mr Ekted - Sun Feb 29, 2004 1:28 am
Post subject:
Access violation is usually attempting to read/write NULL ptr, uninitialized ptr (ie garbage). As cyan said, post your code.
Versetti - Sun Feb 29, 2004 11:06 am
Post subject:
Here is the liked lists I made for it:
Code: Show/Hide

class EntryBoardUser{
public:
   EntryBoardUser();
   ~EntryBoardUser();

   int UserID;         //Never Gets Replaced
   char Name[32];      //Replace1 -- 1
   char Email[100];   //Replace1 -- 2
   char Sig[256];      //Replace1 -- 3
   char title[32];      //Replace1 -- 4
   int posts;         //Replace2 -- 1
   int warnlevel;      //Replace2 -- 2
   int Level;         //Replace2 -- 3
   bool banned;      //Replace2 -- 4 -- (1 = False) (0 = True)
   bool limitread;      //Replace2 -- 5 -- (1 = False) (0 = True)
   ///put the stuff here
};

class BoardUser{
public:
   BoardUser();
   ~BoardUser();

   EntryBoardUser* item;
   BoardUser* next;
   BoardUser* prev;
   //the node is here
};

class ControlBoardUser{
public:
   ControlBoardUser();
   ~ControlBoardUser();

   BoardUser* head;
   BoardUser* tail;
   void clear();
   void remove(char *);
   bool Replace1(int ,char *,char *);
   bool Replace2(int ,char *,int );
};


then my append function is the first thing that gets the error:
Code: Show/Hide

void append(int ID,char *Name,char *Email,bool limit = false,int oplevel = 5,char *title2 = "Newbie"){
   ControlBoardUser *parse;
   if(parse->head && parse->tail){
      parse->head=parse->tail=new BoardUser;
      parse->head->item->UserID = ID;
      memcpy(parse->head->item->Name,Name,32);
      memcpy(parse->head->item->Email,Email,100);
      memcpy(parse->head->item->Sig,0,0);
      strncpy(parse->head->item->title,title2,32);
      parse->head->item->posts = 0;
      parse->head->item->warnlevel = 0;
      parse->head->item->Level = oplevel;
      parse->head->item->banned = false;
      parse->head->item->limitread = limit;
      UserID2++;
   }
   if(parse->tail){
      BoardUser *parse2 = new BoardUser;
      parse2->item->UserID = ID;
      memcpy(parse2->item->Name,Name,32);
      memcpy(parse2->item->Email,Email,100);
      memcpy(parse2->item->Sig,0,0);
      strncpy(parse2->item->title,title2,32);
      parse2->item->posts = 0;
      parse2->item->warnlevel = 0;
      parse2->item->Level = oplevel;
      parse2->item->banned = false;
      parse2->item->limitread = limit;
      UserID2++;
      BoardUser *oldtail = parse->tail;
      parse->tail = parse2;
      parse2->prev = oldtail;
      oldtail->next = parse2;
   }

}


and the error is when I ever try to write to the linked list it will cause that error can you help?
Mr Ekted - Sun Feb 29, 2004 12:21 pm
Post subject:
God I hate C++. Versetti, first of all, you are not showing enough code for me to figure out what you are trying to do. Secondly, the code that you do show is clearly very wrong in many ways. You can't use memcpy() here. Very bad. Very dangerous. Here's a generic function that shows proper linked list "add to tail" functionality...

Code: Show/Hide
void List::AddNewNode (blah blah)
{
Node *node;

if (node = new Node(blah blah))
   {
   if (node->prev = m_tail)
      m_tail = m_tail->next = node;
   else
      m_head = m_tail = node;
   }
}

All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group