Staging
v0.5.1
https://github.com/python/cpython
Revision 6c939cb6f6dfbd273609577b0022542d31ae2802 authored by Benjamin Peterson on 14 April 2014, 02:10:38 UTC, committed by Benjamin Peterson on 14 April 2014, 02:10:38 UTC
1 parent 4624b00
Raw File
Tip revision: 6c939cb6f6dfbd273609577b0022542d31ae2802 authored by Benjamin Peterson on 14 April 2014, 02:10:38 UTC
in scan_once, prevent the reading of arbitrary memory when passed a negative index
Tip revision: 6c939cb
pystrcmp.c
/* Cross platform case insensitive string compare functions
 */

#include "Python.h"

int
PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
{
    if (size == 0)
        return 0;
    while ((--size > 0) &&
           (tolower((unsigned)*s1) == tolower((unsigned)*s2))) {
        if (!*s1++ || !*s2++)
            break;
    }
    return tolower((unsigned)*s1) - tolower((unsigned)*s2);
}

int
PyOS_mystricmp(const char *s1, const char *s2)
{
    while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
        ;
    }
    return (tolower((unsigned)*s1) - tolower((unsigned)*s2));
}
back to top