[sr-dev] Problems with str comparison in ut.h

marius zbihlei marius.zbihlei at 1and1.ro
Thu Apr 22 17:18:52 CEST 2010


Hello

The str_strcmp function does not do a correct lexicographic comparison 
between the received strings:

<verbatim>
/**
 * \brief Compare two str's case sensitive
 * \param str1 first str
 * \param str2 second str
 * \return 0 if both are equal, positive if str1 is greater, negative if 
str2 is greater, -2 on errors
 */
static inline int str_strcmp(const str *str1, const str *str2)
{
    if(str1==NULL || str2==NULL || str1->s ==NULL || str2->s==NULL || 
str1->len<0 || str2->len<0)
    {
        LM_ERR("bad parameters\n");
        return -2;
    }

    if (str1->len < str2->len)
        return -1;
    else if (str1->len > str2->len)
        return 1;
    else
        return strncmp(str1->s, str2->s, str1->len);
}
</verbatim>

in this case str1={"z",1} will be "smaller" then str2={"aa", 2} because 
it's length is smaller . Method is used is various tree implementations...
(same from str_casestrcmp())

Is this "normal" ?

Marius






More information about the sr-dev mailing list