eric pouech (@epo) commented about dlls/mspatcha/pa19.c:
+/* derived from imagehlp for calculating a new coff image checksum. */ +static WORD calc_chksum( + DWORD initial_value, PUCHAR buffer, DWORD size_in_bytes) +{ + DWORD sum; + DWORD words_remaining; + DWORD partial_words; + DWORD partial_sum; + + sum = initial_value; + words_remaining = size_in_bytes / sizeof(WORD); + + for (; words_remaining; sum += HIWORD(partial_sum) + LOWORD(partial_sum)) + { + partial_words = words_remaining; + if (words_remaining > 0x10000) { it could be interesting to explain where the 0x10000 value comes from
and it doesn't look right: each inner loop can add up to sum at most 0x10000 \* 0xffff = 0xffff0000, but the value of sum from a previous loop can be \>= 0x1000 (because of the lo + hi computation) =\> you'll overflow the DWORD of sum reusing tested existing code looks saner to me that reimplementing it -- https://gitlab.winehq.org/wine/wine/-/merge_requests/3870#note_46214