Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 7th, 2005, 11:58 AM   #1
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Function crashes on return

bBool bFileB::open(bString f) {
	fhandle = fopen(f.c_str(), "rb+");
	int currpos = 4;

	if(!fhandle)
		return false;

	int signature;
	fread(&signature, sizeof(int), 1, fhandle);

	if(signature != B_FILEB_HEADER) {
		fclose(fhandle);
		return false;
	}

	fseek(fhandle, 0, SEEK_END);

	if(ftell(fhandle) == 4)
		return true;

	/* read the headers */
	while(true) {
		bFileB_rawsubheader h;
		fseek(fhandle, currpos, SEEK_SET);
		if(feof(fhandle))
			break;

		if(fread(&h, 1, sizeof(bFileB_rawsubheader), fhandle) != sizeof(bFileB_rawsubheader))
			break;

		if(h.signature != B_FILEB_SUBHEADER) {
			fclose(fhandle);
			return false;
		}

		bFileB_subheader h2;
		h2.length = h.length;
		h2.start = currpos + sizeof(bFileB_subheader);
		h2.name = bString(h.name);

		headers.push_back(h2);

		currpos += sizeof(bFileB_subheader) + h.length;
	}

	return true;
}

Ok, so I have this function. The problem is that I get a runtime error (Expression: _CtrIsValidHeapPointer(pUserData)) at the darkred marked line. I think my stack gets fucked up somewhere, but how?

TIA
Polyphemus_ is offline   Reply With Quote
Old Nov 7th, 2005, 1:13 PM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Never mind, I fixed it. It was the string as argument, making a pointer to a string of it did it.
Polyphemus_ is offline   Reply With Quote
Old Nov 8th, 2005, 6:25 AM   #3
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Aren't you supposed to close the filehandle before you break?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Nov 8th, 2005, 7:42 AM   #4
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
Quote:
Originally Posted by nnxion
Aren't you supposed to close the filehandle before you break?
No, the file needs to stay opened.
Polyphemus_ is offline   Reply With Quote
Old Nov 8th, 2005, 10:16 AM   #5
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Hey Poly, did you set an expected beta release date for the OS you're working on yet?
OpenLoop is offline   Reply With Quote
Old Nov 9th, 2005, 3:03 PM   #6
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
You're working on an OS Poly? I'd be glad to help if I had some time, wanted to get some experience with it.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:11 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC