troubleshooting Question

best way to handle a pointer to pointer and assignment method when the pointer return NULL

Avatar of Develprog
Develprog asked on
CEditors IDEs
9 Comments1 Solution532 ViewsLast Modified:
Hi I have a program using pointer of pointer to access at list

this portion of code is giving me error when the return is null.

How can I manage this ?

void Tracertool::updateTracerSet(CCornerList_Int* newCornerList, unsigned char * currentCorner){
	// reset the update status of all the (simple) corners
	map<int, SimpleCorner* >::iterator itSimpleCornerList;
	for (itSimpleCornerList = SimpleCornerList.begin(); itSimpleCornerList!=SimpleCornerList.end(); itSimpleCornerList++){		
		(*itSimpleCornerList).second->isUpdated = false;	
	// for all the current corners
	//unsigned char *currentCorner = newCornerList->get_first();
	//unsigned char **currentCorner = vgt_an_rawcorner_alloc();
	//unsigned char *currentCorner = vgt_an_rawcorner_alloc();
//	strcpy((char*)currentCorner,(const char*) newCornerList->get_first()) ;
	printf("a. value of newCornerList->get_first() =%p\n",newCornerList->get_first());
	printf("b. value of currentCorner after assign =%p\n",currentCorner);
	while (currentCorner !=NULL){
 		//int trackingID = currentCorner->tracking_id;
		long trackingID =0;
 		// search corresponding simple corner
 		map<int, SimpleCorner* >::iterator itcornerTracer= this->SimpleCornerList.find(trackingID);
		// if it exists
		if (itcornerTracer!=SimpleCornerList.end()){		
			(*itcornerTracer).second->isUpdated = true;
			(*itcornerTracer).second->timeElapsedSinceLastUpdate = 0;
			// if the corner exist for a number of frame >= MAX_TRACER_SIZE 
			if ((*itcornerTracer).second->tracer.size() >= (*itcornerTracer).second->tracer_MAX_SIZE ){ 
				//erease first element of real tracer
				delete (*(*itcornerTracer).second->tracer.begin());
				(*itcornerTracer).second->tracer.erase( (*itcornerTracer).second->tracer.begin() );
			//addPointTotracer(currentCorner,(*itcornerTracer).second );
			addPointTotracer(currentCorner,(*itcornerTracer).second );
			//addPointToSmoothtracer(currentCorner,(*itcornerTracer).second, 3);			
			addPointToSmoothtracer(currentCorner,(*itcornerTracer).second, 3);			
		// else create new simple corner
			SimpleCorner* newcorner = new SimpleCorner();
			// add the corner to the intern  list
			this->SimpleCornerList.insert(pair<int, SimpleCorner*>(trackingID, newcorner));

		//currentCorner=*(newCornerList->get_next()); !! ACCESS VIOLATION WHEN FONCTION RETURNS NULL
		//Is this a good way to check NULL condition ? 
		unsigned char ** temp=newCornerList->get_next();
			currentCorner = NULL;
		//3. using strcpy ?  
		//strcpy((char*)currentCorner,(const char*)newCornerList->get_next()) ;



The problem is that when list is at end the line ..t->get_next()); return a NULL so assign it this address to pointer generate Access violation problem.

Is ther another way to do it better ?

Thank you
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros