From 1e0b6995aa2b49b39a6c352b499558d42ca6417c Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Sat, 8 Jul 2006 20:20:55 +0000 Subject: More robust handling of the optional startup.inf file. svn-id: r23436 --- engines/sword2/startup.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/sword2/startup.cpp b/engines/sword2/startup.cpp index 45906dffa3..7ac089e04e 100644 --- a/engines/sword2/startup.cpp +++ b/engines/sword2/startup.cpp @@ -60,8 +60,34 @@ bool Sword2Engine::initStartMenu() { int start_ids[MAX_starts]; char buf[10]; + int lineno = 0; + while (fp.readLine(buf, sizeof(buf))) { - start_ids[_totalScreenManagers] = atoi(buf); + char *errptr; + int id; + + lineno++; + id = strtol(buf, &errptr, 10); + + if (*errptr) { + warning("startup.inf:%d: Invalid string '%s'", lineno, buf); + continue; + } + + if (!_resman->checkValid(id)) { + warning("startup.inf:%d: Invalid resource %d", lineno, id); + continue; + } + + if (_resman->fetchType(id) != SCREEN_MANAGER) { + byte name[NAME_LEN]; + + warning("startup.inf:%d: '%s' (%d) is not a screen manager", lineno, _resman->fetchName(id, name), id); + continue; + } + + start_ids[_totalScreenManagers] = id; + if (++_totalScreenManagers >= MAX_starts) { warning("Too many entries in startup.inf"); break; @@ -86,17 +112,10 @@ bool Sword2Engine::initStartMenu() { debug(2, "Querying screen manager %d", _startRes); // Open each one and run through the interpreter. Script 0 is - // the query request script - - // if the resource number is within range & it's not a null - // resource - // - need to check in case un-built sections included in - // start list + // the query request script. We have already made reasonably + // sure the resource is ok. - if (_resman->checkValid(_startRes)) { - _logic->runResScript(_startRes, 0); - } else - warning("Start menu resource %d invalid", _startRes); + _logic->runResScript(_startRes, 0); } return 1; -- cgit v1.2.3