Invalid map number in recorded demo

From DoomWiki.org

In the last released version of Heretic (and possibly earlier versions), it is possible to record a demo which has an invalid map number saved within it. Attempting to replay the demo will replay it on an unpredictable map slot and so it will appear to desync.

How to reproduce[edit]

You must invoke Heretic using -warp and -record arguments, but only pass one argument to -warp, which expects two:

heretic -warp 1 -record zomg3

The game will start on Episode 1, Map 1, despite you not having specified the arguments to -warp correctly.

Attempting to play back the demo however will result in playback on a different map (in this case, E1M9).

Cause[edit]

When Heretic starts up, it handles the -warp argument before -record. The code in D_DoomMain to handle warping looks at two arguments that follow -warp in the command line but does not make sure that they are valid numbers. Instead the numeric value is used, whatever that is.

   p = M_CheckParmWithArgs("-warp", 2);
   if (p && p < myargc - 2)
   {
       startepisode = myargv[p + 1][0] - '0';
       startmap = myargv[p + 2][0] - '0';

In the above example, it would treat '1' as the episode number and '-' as the map number, which equals 45.

The -record argument is handled next, by G_RecordDemo which simply writes out the value of the map number to the demo, and so in this case writes out 45.

When the game starts, later code has ignored the invalid episode/map number and so the game starts on E1M1.