From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eigenstate.org ([206.124.132.107]) by ewsd; Thu Nov 21 04:10:36 EST 2019 Received: from eigenstate.org (localhost [127.0.0.1]) by eigenstate.org (OpenSMTPD) with ESMTP id f417c2d0 for <9front@9front.org>; Thu, 21 Nov 2019 01:10:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=eigenstate.org; h= message-id:to:subject:date:from:mime-version:content-type :content-transfer-encoding; s=mail; bh=bWXNCdqdi4felAPYQ+lqqCWo5 vo=; b=C4fgQCy8UGHkCEREL47Xvp2qxOpJX7jJr08rxmQaE7enlPVG28YBuSSIZ U75n9h7MmmV20JWIJigb8FaUl2N0UB+ukzZ9njRww+J9bJVYBAu6FFblftV2kKTT AxqBWj7KT1/CqMzlo0V/hFlOJB0Isl/lK79sn59kwDH74fmlp4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=eigenstate.org; h=message-id :to:subject:date:from:mime-version:content-type :content-transfer-encoding; q=dns; s=mail; b=fh7i0V1mry2X+YJqP4F PQDFzNpjLU+X4SpWFQVlkMA9Wjaw5laGoA1IV/l4yOFI8lOmKIdqYNO031ktPWqY FwbwgGViQTqrT3sOFc9Mk2kB9yLlKCBOweb0YPVHwIXXxd8YBaFQ1JidONBNicYD Q9vMRAwEWbxOoU8N7fyfxXms= Received: from abbatoir.hsd1.ca.comcast.net (c-76-21-119-139.hsd1.ca.comcast.net [76.21.119.139]) by eigenstate.org (OpenSMTPD) with ESMTPSA id edf2ba35 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Thu, 21 Nov 2019 01:10:34 -0800 (PST) Message-ID: <3538A24A05D19F1D333569AA901FA1E4@eigenstate.org> To: 9front@9front.org Subject: fix ref822 Date: Thu, 21 Nov 2019 01:10:33 -0800 From: ori@eigenstate.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: webscale transactional session extension DOM database We were getting nils in the list when there were tons of references, since the memset was wrong. We wanted to clear a + i - j. But the code seemed confusing regardless, so I simplified it. It seems to work for me. It's late, I'm tired, beware off-by-onee errors. diff -r 663578b51263 sys/src/cmd/upas/fs/dat.h --- a/sys/src/cmd/upas/fs/dat.h Tue Nov 19 12:31:42 2019 -0800 +++ b/sys/src/cmd/upas/fs/dat.h Thu Nov 21 01:04:17 2019 -0800 @@ -120,7 +120,7 @@ char *unixheader; char *unixfrom; char *date822; - char *references[Nref]; + char *references[Nref]; /* nil terminated unless full */ /* mime info */ char *charset; diff -r 663578b51263 sys/src/cmd/upas/fs/mbox.c --- a/sys/src/cmd/upas/fs/mbox.c Tue Nov 19 12:31:42 2019 -0800 +++ b/sys/src/cmd/upas/fs/mbox.c Thu Nov 21 01:04:17 2019 -0800 @@ -880,7 +880,7 @@ ref822(Message *m, Header *h, char*, char *p) { char **a, *s, *f[Nref + 1]; - int i, j, k, n; + int i, j, n; s = strdup(skipwhite(p + h->len)); n = getfields(s, f, nelem(f), 1, "<> \n\t\r,"); @@ -889,26 +889,24 @@ n = uniqarray(f, n, 0); a = m->references; for(i = 0; i < Nref; i++) - if(a[i] == 0) + if(a[i] == nil) break; /* * if there are too many references, drop from the beginning * of the list. */ - j = i + n - Nref; - if(j > 0){ - if(j > Nref) - j = Nref; - for(k = 0; k < j; k++) - free(a[k]); - memmove(a, a + j, sizeof a[0]*(Nref - j)); - memset(a + j, 0, Nref - j); - i -= j; + if(i + n > Nref){ + for(i = 0; i < n; i++) + free(a[i]); + for(i = n; i < Nref; i++) + a[i - n] = a[i]; } for(j = 0; j < n;) a[i++] = strdup(f[j++]); + n = uniqarray(a, i, 1); + if(n < Nref) + a[n] = nil; free(s); - uniqarray(a, i, 1); return (char*)~0; }