From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eigenstate.org ([206.124.132.107]) by ewsd; Fri Nov 22 13:39:29 EST 2019 Received: from eigenstate.org (localhost [127.0.0.1]) by eigenstate.org (OpenSMTPD) with ESMTP id 87154cc4; Fri, 22 Nov 2019 10:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=eigenstate.org; h= message-id:to:subject:date:from:in-reply-to:mime-version :content-type:content-transfer-encoding; s=mail; bh=UcQ57rvG5vSQ GGJF0wA5zrs0op4=; b=D2StgP8326DTf6eNQIMlYRouEKomItilGeMOlhOzaZfA cRrTmasGgEH5VruOoJXC8pyACcGQImsCxwRPrbb3UFDqpdNfi1tuYEb3+0IQPv40 s/KeEK1Ncvl3ieGDgxOH/rkxDUFFX6+jrelmqkrlfERX02mqczStci4W2VDFw3k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=eigenstate.org; h=message-id :to:subject:date:from:in-reply-to:mime-version:content-type :content-transfer-encoding; q=dns; s=mail; b=bewqexej+wdHeSaDWv6 FsCIB6jubLGdWtFcDDkuxM3mXvBqDienYEgxBdy9KQENr0pm5ANtJcfo5ymi7jYM TVRuK6pmQg+IFsleXZPb+DUMLEgfPizTrqXzql+7ppWcWhelKPhHUk9jXurZoVer v8X7W7A5YXpHBSma9ZjrB4fs= 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 e1659b60 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO); Fri, 22 Nov 2019 10:39:26 -0800 (PST) Message-ID: <663176CA83C9DF3BA009A5067FE7C47A@eigenstate.org> To: cinap_lenrek@felloff.net, 9front@9front.org Subject: Re: [9front] fix ref822 Date: Fri, 22 Nov 2019 10:39:25 -0800 From: ori@eigenstate.org In-Reply-To: 4F2E28EFD56B89BE598EA209856361F5@felloff.net 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: encrypted open-source extension-scale ACPI over SVG cloud storage injection generator > i think this is also wrong: > > + if(i + n > Nref){ > + for(i = 0; i < n; i++) > + free(a[i]); > + for(i = n; i < Nref; i++) > + a[i - n] = a[i]; > } > > i is number of entries in a[], n is number of entries in f[]. if we got > like i = 1 and n = Nref, we'd want to remove 1 item from a because: > > i + n - Nref == 1 + Nref - Nref == 1 > > also, i think the uniqarray() approach is wrong. we probably want to > deduplicate while we insert into a. we should never populate m->references > with duplicate items in the first place. > > delete uniquearray() and instead just do it like this: > > a = m->references; > n = tokenize(f, ....); > > for(i=0; i for(j=0; j if(a[j] == nil || strcmp(a[j], f[i]) == 0) > break; > } > if(j == Nref){ > // handle full case, shift a by one > } > > // now a[j] can be: nil = slot free, > a[j] = f[i]; // put into array > } > > -- > cinap Actually, ignore that last message. Yeah, this is better, though it has produces marginally different results. Updated patch: diff -r 8b2040ba4785 sys/src/cmd/upas/fs/mbox.c --- a/sys/src/cmd/upas/fs/mbox.c Fri Nov 22 17:29:35 2019 +1030 +++ b/sys/src/cmd/upas/fs/mbox.c Fri Nov 22 10:38:48 2019 -0800 @@ -857,25 +857,6 @@ return rtrim(strdup(skipwhite(p + h->len))); } -/* - * firefox, e.g. doesn't keep references unique - */ -static int -uniqarray(char **a, int n, int allocd) -{ - int i, j; - - for(i = 0; i < n; i++) - for(j = i + 1; j < n; j++) - if(strcmp(a[i], a[j]) == 0){ - if(allocd) - free(a[j]); - memmove(a + j, a + j + 1, sizeof *a*(n - (j + 1))); - a[--n] = 0; - } - return n; -} - static char* ref822(Message *m, Header *h, char*, char *p) { @@ -886,26 +867,26 @@ n = getfields(s, f, nelem(f), 1, "<> \n\t\r,"); if(n > Nref) n = Nref; - n = uniqarray(f, n, 0); a = m->references; for(i = 0; i < Nref; i++) if(a[i] == nil) break; /* * if there are too many references, drop from the beginning - * of the list. + * of the list. If someone else has a duplicate, we keep the + * old duplicate. */ - 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(i = 0; i < n; i++){ + for(j = 0; j < Nref; j++) + if(a[j] == nil || strcmp(a[j], f[i]) == 0) + break; + if(j == Nref){ + free(a[0]); + memmove(&a[0], &a[1], (Nref - 1) * sizeof(a[0])); + j--; + } + a[j] = strdup(f[i]); } - for(j = 0; j < n;) - a[i++] = strdup(f[j++]); - n = uniqarray(a, i, 1); - if(n < Nref) - a[n] = nil; free(s); return (char*)~0; }