Skip to content

Commit

Permalink
MOHAWK: Don't initialize a null pointer, to make VS2010 happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK committed Apr 21, 2011
1 parent f236ecb commit 44e79c7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion engines/mohawk/myst_stacks/selenitic.cpp
Expand Up @@ -816,7 +816,7 @@ void Selenitic::o_soundLockEndMove(uint16 op, uint16 var, uint16 argc, uint16 *a
debugC(kDebugScript, "Opcode %d: Sound lock end move", op);

MystResourceType10 *slider = soundLockSliderFromVar(var);
uint16 *value = 0;
uint16 *value = &_state.soundLockSliderPositions[0];

switch (var) {
case 20: // Sound lock sliders
Expand All @@ -834,6 +834,9 @@ void Selenitic::o_soundLockEndMove(uint16 op, uint16 var, uint16 argc, uint16 *a
case 24:
value = &_state.soundLockSliderPositions[4];
break;
default:
error("Incorrect var value for Selenitic opcode 114");
break;
}

uint16 stepped = 12 * (*value / 12) + 6;
Expand Down

5 comments on commit 44e79c7

@lordhoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if you made that "return;" instead of "break;" after the error it might very well be that MSVC won't complain even when you initialize value to 0.

@wjp
Copy link
Contributor

@wjp wjp commented on 44e79c7 Apr 21, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break or return shouldn't be necessary at all, even in MSVC, since error() is marked __declspec(noreturn).

@lordhoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propaly, maybe it just doesn't detect it then.

@Templier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It complains about the value pointer being used without being initialized on line 839, so you either need to set it to a proper value (that is never actually used if I understand the code properly) or add an error like you did, but only one of those is actually required.

I think the error in the default case is better, and the error call is all that is needed, no need for return or break, or initializing the pointer to a default value.

@lordhoto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah in this case it is fine to not add a return after error, still in general you want to do that, since we also support compilers which do not feature any noreturn marking, like MIPSpro IIRC. That way you avoid many nasty warnings/errors on such systems.

Please sign in to comment.