const struct tr_key_struct * a = va;
const struct tr_key_struct * b = vb;
- ret = memcmp (a->str, b->str, a->len);
+ ret = memcmp (a->str, b->str, MIN (a->len, b->len));
if (!ret && (a->len != b->len))
ret = a->len < b->len ? -1 : 1;
{
size_t len = o->longName ? strlen (o->longName) : 0;
- if ((matchlen < len) && !memcmp (str, "--", 2)
- && !memcmp (str + 2, o->longName, len)
+ if ((matchlen < len)
+ && (str[0] == '-')
+ && (str[1] == '-')
+ && !strncmp (str+2, o->longName, len)
&& (str[len + 2] == '\0' || (o->has_arg && str[len + 2] == '=')))
{
matchlen = len;
len = o->shortName ? strlen (o->shortName) : 0;
- if ((matchlen < len) && !memcmp (str, "-", 1)
- && !memcmp (str + 1, o->shortName, len)
+ if ((matchlen < len)
+ && (str[0] == '-')
+ && !strncmp (str+1, o->shortName, len)
&& (str[len + 1] == '\0' || o->has_arg))
{
matchlen = len;