1
1
/* vim:set cin ft=c sw=4 sts=4 ts=8 et ai cino=Ls\:0t0(0 : -*- mode:c;fill-column:80;tab-width:8;c-basic-offset:4;indent-tabs-mode:nil;c-file-style:"k&r" -*-*/
2
- /* Last modified by Alex Smith, 2015-11-11 */
2
+ /* Last modified by Alex Smith, 2017-06-28 */
3
3
/* Copyright (c) Daniel Thaler, 2011. */
4
4
/* NetHack may be freely redistributed. See license for details. */
5
5
@@ -472,7 +472,7 @@ mdiffcmd_width(const struct memfile *mf, struct mdiff_command_instance *mdci,
472
472
static void
473
473
mdiffwritecmd (struct memfile * mf , struct mdiff_command_instance * mdci )
474
474
{
475
- int widenings , usedbits , usedbytes , i ;
475
+ int widenings , usedbits , usedbytes , splitbytes , i ;
476
476
477
477
/* Count the number of widenings we need. */
478
478
usedbytes = mdiffcmd_width (mf , mdci , & widenings );
@@ -490,15 +490,24 @@ mdiffwritecmd(struct memfile *mf, struct mdiff_command_instance *mdci)
490
490
usedbits += mdiff_command_sizes [mdci -> command ].arg2 ;
491
491
encoding |= mdci -> arg2 ;
492
492
493
- /* Add the encoding of arg1. */
493
+ /* Add the encoding of arg1.
494
+
495
+ We have to be careful here: the MRU prefix + arg2 + arg1 might come to
496
+ more than 8 bytes (e.g. in the case of an eof_crc32 command with a very
497
+ large copy count). As such, we split the largest possible whole number
498
+ of bytes off from the end of arg1. */
494
499
usedbits = usedbytes * 8 - usedbits ;
495
- encoding <<= usedbits ;
500
+ splitbytes = usedbits / 8 ;
501
+ encoding <<= usedbits % 8 ;
496
502
unsigned long long arg1_2c = mdci -> arg1 & ((1ULL << usedbits ) - 1 );
497
- encoding |= arg1_2c ;
503
+ encoding |= arg1_2c >> ( splitbytes * 8 ) ;
498
504
499
- i = usedbytes ;
505
+ i = usedbytes - splitbytes ;
500
506
while (i -- )
501
507
mdiffwrite8 (mf , encoding >> (i * 8 ));
508
+ i = splitbytes ;
509
+ while (i -- )
510
+ mdiffwrite8 (mf , arg1_2c >> (i * 8 ));
502
511
503
512
if (debuglog ) {
504
513
fprintf (debuglog , "%s %" PRIdLEAST64 " %" PRIuLEAST64 " (" ,
0 commit comments