Skip to content

Commit

Permalink
SCI: Got rid of VERIFY() and removed some newlines in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Mar 14, 2011
1 parent 75319af commit ca1f9a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
18 changes: 10 additions & 8 deletions engines/sci/engine/script.cpp
Expand Up @@ -70,7 +70,7 @@ void Script::init(int script_nr, ResourceManager *resMan) {
Resource *script = resMan->findResource(ResourceId(kResourceTypeScript, script_nr), 0);

if (!script)
error("Script %d not found\n", script_nr);
error("Script %d not found", script_nr);

_localsOffset = 0;
_localsBlock = NULL;
Expand Down Expand Up @@ -257,9 +257,8 @@ Object *Script::scriptObjInit(reg_t obj_pos, bool fullObjectInit) {
if (getSciVersion() < SCI_VERSION_1_1 && fullObjectInit)
obj_pos.offset += 8; // magic offset (SCRIPT_OBJECT_MAGIC_OFFSET)

VERIFY(obj_pos.offset < _bufSize, "Attempt to initialize object beyond end of script\n");

VERIFY(obj_pos.offset + kOffsetFunctionArea < (int)_bufSize, "Function area pointer stored beyond end of script\n");
if (obj_pos.offset >= _bufSize)
error("Attempt to initialize object beyond end of script");

// Get the object at the specified position and init it. This will
// automatically "allocate" space for it in the _objects map if necessary.
Expand Down Expand Up @@ -327,8 +326,9 @@ void Script::relocateSci0Sci21(reg_t block) {
heapOffset = _scriptSize;
}

VERIFY(block.offset < (uint16)heapSize && READ_SCI11ENDIAN_UINT16(heap + block.offset) * 2 + block.offset < (uint16)heapSize,
"Relocation block outside of script\n");
if (block.offset >= (uint16)heapSize ||
READ_SCI11ENDIAN_UINT16(heap + block.offset) * 2 + block.offset >= (uint16)heapSize)
error("Relocation block outside of script");

int count = READ_SCI11ENDIAN_UINT16(heap + block.offset);
int exportIndex = 0;
Expand Down Expand Up @@ -418,7 +418,8 @@ uint16 Script::validateExportFunc(int pubfunct, bool relocate) {
offset = relocateOffsetSci3(pubfunct * 2 + 22);
}

VERIFY(offset < _bufSize, "invalid export function pointer");
if (offset >= _bufSize)
error("Invalid export function pointer");

// Check if the offset found points to a second export table (e.g. script 912
// in Camelot and script 306 in KQ4). Such offsets are usually small (i.e. < 10),
Expand All @@ -432,7 +433,8 @@ uint16 Script::validateExportFunc(int pubfunct, bool relocate) {
if (secondExportTable) {
secondExportTable += 3; // skip header plus 2 bytes (secondExportTable is a uint16 pointer)
offset = READ_SCI11ENDIAN_UINT16(secondExportTable + pubfunct);
VERIFY(offset < _bufSize, "invalid export function pointer");
if (offset >= _bufSize)
error("Invalid export function pointer");
}
}

Expand Down
8 changes: 4 additions & 4 deletions engines/sci/engine/seg_manager.cpp
Expand Up @@ -152,7 +152,8 @@ Script *SegManager::allocateScript(int script_nr, SegmentId *segid) {
}

void SegManager::deallocate(SegmentId seg) {
VERIFY(check(seg), "invalid seg id");
if (!check(seg))
error("SegManager::deallocate(): invalid segment ID");

SegmentObj *mobj = _heap[seg];

Expand Down Expand Up @@ -359,9 +360,8 @@ LocalVariables *SegManager::allocLocalsSegment(Script *scr) {

if (scr->_localsSegment) {
locals = (LocalVariables *)_heap[scr->_localsSegment];
VERIFY(locals != NULL, "Re-used locals segment was NULL'd out");
VERIFY(locals->getType() == SEG_TYPE_LOCALS, "Re-used locals segment did not consist of local variables");
VERIFY(locals->script_id == scr->getScriptNumber(), "Re-used locals segment belonged to other script");
if (!locals || locals->getType() != SEG_TYPE_LOCALS || locals->script_id != scr->getScriptNumber())
error("Invalid script locals segment while allocating locals");
} else
locals = (LocalVariables *)allocSegment(new LocalVariables(), &scr->_localsSegment);

Expand Down
9 changes: 0 additions & 9 deletions engines/sci/engine/seg_manager.h
Expand Up @@ -35,15 +35,6 @@

namespace Sci {

/**
* Verify the the given condition is true, output the message if condition is false, and exit.
* @param cond condition to be verified
* @param msg the message to be printed if condition fails
*/
#define VERIFY( cond, msg ) if (!(cond)) {\
error("%s, line, %d, %s", __FILE__, __LINE__, msg); \
}

/**
* Parameters for getScriptSegment().
*/
Expand Down

0 comments on commit ca1f9a0

Please sign in to comment.