createIrrXMLReader, does not return NULL

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
ishikawa
Posts: 4
Joined: Thu Apr 19, 2007 2:22 pm

createIrrXMLReader, does not return NULL

Post by ishikawa »

I found a bug in a irrXML:

Code: Select all

createIrrXMLReader(char* filename);
This function returns an instance to class which is used to read xml files. It should return a NULL pointer if the file given in char* variable doesn't exist - but it doesn't.

Let's have a closer look at createIrrXMLReader function:

Code: Select all

IrrXMLReader* createIrrXMLReader(const char* filename)

{
		return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename)); 

}
Whoa? It does not even check if the file exist! If so, it ever won't return NULL pointer. What should we do? Let's just add this check:

Code: Select all

IrrXMLReader* createIrrXMLReader(const char* filename)

{
	FILE* file;
	
	file = fopen(filename, "rb");
	
	if(!file)
		return NULL;
	else
		return new CXMLReaderImpl<char, IXMLBase>(new CFileReadCallBack(filename)); 

}
Now it's fine. Aren't I'm briliant? :P

Geez, sorry for my poor english ;[
"Silver chip in my brain, makes me feeling free. While connected with cold steel, I'm seting up." Cyberpunk
Post Reply