From: ori@eigenstate.org
To: 9front@9front.org
Subject: fix ref822
Date: Thu, 21 Nov 2019 01:10:33 -0800 [thread overview]
Message-ID: <3538A24A05D19F1D333569AA901FA1E4@eigenstate.org> (raw)
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;
}
reply other threads:[~2019-11-21 9:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3538A24A05D19F1D333569AA901FA1E4@eigenstate.org \
--to=ori@eigenstate.org \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).