c = *name;
}
if (namlen == 0) {
- if (name == *namep)
+ if (name == *namep || n > p->body_size)
return -1;
*namep = name;
return n;
for (i = 0; i < p->body_size; i++) {
if (!subseq_match(nam, namlen, p->body[i]->name))
continue;
- if (slen == 0 || p->body[i]->name.len < slen)
+ if (slen == 0 || p->body[i]->name.len < slen) {
s = i;
+ slen = p->body[i]->name.len;
+ }
if (s >= 0 && p->body[i] != p->body[s] &&
p->body[i]->name.len == p->body[s]->name.len)
/* not unique, so s cannot be used */
}
if (s < 0)
return -1;
- if (n == 0);
+ if (n == 0)
n = 1;
for (i = 0; i < p->body_size; i++)
if (p->body[i] == p->body[s]) {
if (n == 0)
break;
}
- if (n > 1)
+ if (n > 0 || i == p->body_size)
return -1;
*namep = name;
return i + 1;