* fix ref822
@ 2019-11-21 9:10 ori
0 siblings, 0 replies; only message in thread
From: ori @ 2019-11-21 9:10 UTC (permalink / raw)
To: 9front
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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-11-21 9:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-21 9:10 fix ref822 ori
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).