AW: octstr_compare

Jörg Pommnitz <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
I'm not sure, but I think a NULL octstr would already fail the
sems_valid test and cause an assertion.

-----Ursprüngliche Nachricht-----
Von: Yury Mikhienko [mailto:[email protected]]
Gesendet: Mittwoch, 10. März 2004 11:16
An: [email protected]
Betreff: octstr_compare


Hi All!

What are think about the add following code into octstr.c/octstr_compare?

int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
{
    int ret;
    long len;

    seems_valid(ostr1);
    seems_valid(ostr2);

+    if ((ostr1 == NULL) && (ostr2 == NULL))
+       return 0;
        
    if (ostr1->len < ostr2->len)
        len = ostr1->len;
    else
        len = ostr2->len;

    if (len == 0) {
        if (ostr1->len == 0 && ostr2->len > 0)
            return -1;
        if (ostr1->len > 0 && ostr2->len == 0)
            return 1;
        return 0;
    }

    ret = memcmp(ostr1->data, ostr2->data, len);
    if (ret == 0) {
        if (ostr1->len < ostr2->len)
            ret = -1;
        else if (ostr1->len > ostr2->len)
            ret = 1;
    }
    return ret;
}


-- 
 
Best regards,
Yury Mikhienko.
IT ERP group head, ZAO "Mobikom-Kavkaz"
tel: (8632) 704188
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.