From: Knut F. <Knu...@gm...> - 2010-11-10 07:43:39
|
[2010-11-10 00:02] Miquel Garriga <gbm...@gm...>: > Function Origin800Parser::findStringPos when the passed string > is not found leaves the 'get pointer' of file close to (but not at) > the EOF. Patches solve possible problems derived from this. To be precise, the patches resolve *some* of the problems caused by this. There are definitely more bugs lurking in the general vicinity. I'd say the problem is really findStringPos(). If it finds the string searched for, it seeks to the position where the search started and returns the position where the match occured, but if the string is *not* found, it leaves the file almost (but not quite) at EOF and returns that position. Nobody, apparantly including the authors of that code, would expect that. Just search through the callers of findStringPos and see how many of them handle the case of not finding the string correctly (without your patches, I'm counting zero of them). What findStringPos() *should* do is guarantee that the read position does not change (i.e. seekg(startPos) before any return) and clearly indicate failure. There are different conventions for that (-1, a special value a la std::string::npos, returning bool or error code and writing the actual result to a pointer as offered by the GSL, throwing an exception). I think it would help if we could try to stick to one such convention. Knut |