Crash when writing an XmlElement to a FileOutputStream


#1

It’s friday evening, so it may just be that I’m not thinking straight, but I think I’ve discovered a bug when writing an XmlElement on one line to a FileOutputStream.

Try the following code in a basic non-gui introjucer’d app:

[code]int main (int argc, char* argv[])
{
File outputFile("~test_file.txt");
ScopedPointer stream (outputFile.createOutputStream());
XmlElement element(“foobar”);
element.writeToStream(*stream, juce::String::empty, true, false);

return 0;

}[/code]
The key point here is that we are calling writeToStream with allOnOneLine set to true. This in turns calls XmlElement::writeElementAsText, with an indentation level of -1, which ultimately falls over when, in FileOutputStream::writeRepeatedByte with numBytes = -1, the program tries to :

memset (buffer + bytesInBuffer, byte, (size_t) numBytes);


#2

Your stream is probably a null pointer.


#3

No, I’ve checked that: I only skimped on error checking here so I could show the bug in as simple a program as possible.


#4

Oh! Sorry, you’re right, looks like a little bugette there! Thanks, I’ll get that sorted out right away!