fix ref822 again: remove uniqarray(), fix case with many entries in 'n'.
This commit is contained in:
parent
cac853084c
commit
6c2017f6a6
1 changed files with 12 additions and 31 deletions
|
@ -857,25 +857,6 @@ copy822(Message*, Header *h, char*, char *p)
|
||||||
return rtrim(strdup(skipwhite(p + h->len)));
|
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*
|
static char*
|
||||||
ref822(Message *m, Header *h, char*, char *p)
|
ref822(Message *m, Header *h, char*, char *p)
|
||||||
{
|
{
|
||||||
|
@ -886,26 +867,26 @@ ref822(Message *m, Header *h, char*, char *p)
|
||||||
n = getfields(s, f, nelem(f), 1, "<> \n\t\r,");
|
n = getfields(s, f, nelem(f), 1, "<> \n\t\r,");
|
||||||
if(n > Nref)
|
if(n > Nref)
|
||||||
n = Nref;
|
n = Nref;
|
||||||
n = uniqarray(f, n, 0);
|
|
||||||
a = m->references;
|
a = m->references;
|
||||||
for(i = 0; i < Nref; i++)
|
for(i = 0; i < Nref; i++)
|
||||||
if(a[i] == nil)
|
if(a[i] == nil)
|
||||||
break;
|
break;
|
||||||
/*
|
/*
|
||||||
* if there are too many references, drop from the beginning
|
* 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++){
|
||||||
for(i = 0; i < n; i++)
|
for(j = 0; j < Nref; j++)
|
||||||
free(a[i]);
|
if(a[j] == nil || strcmp(a[j], f[i]) == 0)
|
||||||
for(i = n; i < Nref; i++)
|
break;
|
||||||
a[i - n] = a[i];
|
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);
|
free(s);
|
||||||
return (char*)~0;
|
return (char*)~0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue