From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx.sdf.org ([205.166.94.24]) by ewsd; Sat Nov 21 10:45:29 -0500 2020 Received: from sdf.org (IDENT:nicolagi@faeroes.freeshell.org [205.166.94.9]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 0ALFdPa3027812 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO) for <9front@9front.org>; Sat, 21 Nov 2020 15:39:25 GMT Received: (from nicolagi@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 0ALFdbJC001377 for 9front@9front.org; Sat, 21 Nov 2020 15:39:37 GMT Message-ID: <98B0A90C39B4474EE7DEEFD6C04B56B9@sdf.org> To: 9front@9front.org Subject: MOVE implementation in games/mix Date: Sat, 21 Nov 2020 15:39:21 +0000 From: nicolagi@sdf.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: information plugin hypervisor method Largely unimportant but I'll share anyway... I was toying with games/mix to do some exercises from TACP. It seems to me MOVE shouldn't be implemented with memcpy() but with an explicit for loop, in order to surely comply with the description of the behavior in case of overlapping memory regions at page 135. It seems to me that this is expected to be exploited in exercise 16. I've changed my copy of games/mix with the below; probably not idiomatic C but seems to do the trick. Am I totally wrong? diff -r 551ecd2fd50b sys/src/games/mix/mix.c --- a/sys/src/games/mix/mix.c Thu Nov 19 23:05:26 2020 -0800 +++ b/sys/src/games/mix/mix.c Sat Nov 21 15:36:38 2020 +0000 @@ -736,7 +736,10 @@ d = mval(ri[1], 0, MASK2); if(d < 0 || d > 4000) vmerror("Bad address MOVE %d", d); - memcpy(cells+d, cells+s, f*sizeof(u32int)); + u32int *p = cells + d, *q = cells + s; + while(p < cells+d+f) + *p++ = *q++; + /* memcpy(cells+d, cells+s, f*sizeof(u32int)); */ d += f; d &= MASK2; ri[1] = d < 0 ? -d|SIGNB : d;