(nstr_string_ok): New.

(nstr_comp): Use it to fix oops on `des='.  Reported by Doug Wescott.
This commit is contained in:
Markus Armbruster 2005-06-09 22:12:32 +00:00
parent fbf9f15bbb
commit db9098042d

View file

@ -127,12 +127,10 @@ nstr_comp(struct nscstr *np, int len, int type, char *str)
* must name selectors. * must name selectors.
*/ */
if (!nstr_resolve_id(&np->lft, ca, lft_caidx, if (!nstr_resolve_id(&np->lft, ca, lft_caidx,
nstr_promote(ca[rgt_caidx].ca_type) nstr_string_ok(ca, rgt_caidx)))
== NSC_STRING))
return -1; return -1;
if (!nstr_resolve_id(&np->rgt, ca, rgt_caidx, if (!nstr_resolve_id(&np->rgt, ca, rgt_caidx,
nstr_promote(ca[lft_caidx].ca_type) nstr_string_ok(ca, lft_caidx)))
== NSC_STRING))
return -1; return -1;
} }
@ -336,9 +334,9 @@ nstr_match_ca(struct valstr *val, struct castr *ca)
/* /*
* Match VAL in a selector's values, return its (non-negative) value. * Match VAL in a selector's values, return its (non-negative) value.
* TYPE is the context type, a file type. * TYPE is the context type, a file type.
* CA is ef_cadef(TYPE). * CA is ef_cadef(TYPE). If it is null, then IDX must be negative.
* Match values of selector descriptor CA[IDX], provided CA is not * Match values of selector descriptor CA[IDX], provided IDX is not
* null and IDX is not negative. * negative.
* Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are * Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
* several. * several.
* TODO: This is just a stub and works only for NSC_TYPEID. * TODO: This is just a stub and works only for NSC_TYPEID.
@ -362,6 +360,16 @@ nstr_match_val(struct valstr *val, int type, struct castr *ca, int idx)
return typematch(id, type); return typematch(id, type);
} }
/*
* Can CA[IDX] be compared to a string?
* Return 0 for negative IDX.
*/
int
nstr_string_ok(struct castr *ca, int idx)
{
return idx >= 0 && nstr_promote(ca[idx].ca_type) == NSC_STRING;
}
/* /*
* Change VAL to resolve identifier to selector or string. * Change VAL to resolve identifier to selector or string.
* Return VAL on success, NULL on error. * Return VAL on success, NULL on error.