saurabhshri/simple-yet-powerful-srt-subtitle-parser-cpp

Some instability witnessed

Closed this issue · 1 comments

I'm finding that if the timestamp contains a period instead of a comma that the parser crashes, without throwing an exception.
For example 00:00:02.000 instead of 00:00:02,000.

Now I realize that the proper SubRip format requires commas, but it would be nice if an exception was thrown. It makes me wonder if other format errors would also cause faults.

I'm not an STL expert by any stretch, and learned that vector::at will throw an 'out of range' exception whereas vector::operator[] will just crash. So this explains what is going on here, and why.
(Ref: http://www.cplusplus.com/forum/general/34754/)

I chose to deal with this by just checking the return from split():

	if (secs.size() != 2)
	{
		throw std::runtime_error("Invalid timestamp: " + value);
	}

Above that I also do

	if (t.size() != 3)
	{
		throw std::runtime_error("Invalid timestamp: " + value);
	}

That way I don't have to worry that someone will make a typo while editing their SRTs and then look for me when my program crashes :-)