(trunk libT) #5316 'UMR in quark, tr-getopt code': fixed.

This commit is contained in:
Jordan Lee 2013-04-13 18:29:56 +00:00
parent 908af43d99
commit f1d616d37c
2 changed files with 8 additions and 5 deletions

View File

@ -399,7 +399,7 @@ compareKeys (const void * va, const void * vb)
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;

View File

@ -149,8 +149,10 @@ findOption (const tr_option * opts,
{
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;
@ -160,8 +162,9 @@ findOption (const tr_option * opts,
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;