This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyOS_mystricmp is broken
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: PyOS_mystricmp advances pointers too far
View: 41524
Assigned To: Nosy List: iritkatriel, kakkoko, vstinner
Priority: normal Keywords: patch

Created on 2014-09-03 09:04 by kakkoko, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pystrcmp.c.patch kakkoko, 2014-09-03 09:04
Messages (6)
msg226303 - (view) Author: Masahiro Konishi (kakkoko) Date: 2014-09-03 09:04
int x = PyOS_mystricmp("foo", "none");
expected: x < 0
actual:   x == 0

    while (*s1 && (tolower((unsigned)*s1++) == tolower((unsigned)*s2++))) {
        ;
    }
    return (tolower((unsigned)*s1) - tolower((unsigned)*s2));

The while-loop is finished when *s1 != *s2 (ex. *s1 == 'f', *s2 == 'n'), but s1 and s2 already point to next characters (ex. *s1 == 'o', *s2 == 'o'), so PyOS_mystricmp returns difference between these characters.
msg226305 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-09-03 09:08
I didn't know PyOS_mystrnicmp() and PyOS_mystricmp() functions! They are not used in Python source code. They are not documented, but they are exported in pystrcmp.h which is included in the main Python.h header.
msg226306 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-09-03 09:13
Also, they aren't safe with the Turkish "i".
msg226307 - (view) Author: Masahiro Konishi (kakkoko) Date: 2014-09-03 09:15
You can find PyOS_stricmp from here:
  https://docs.python.org/3/c-api/conversion.html

And PyOS_stricmp is PyOS_mystricmp when MS_WINDOWS is not defined.

Include/pystrcmp.h:
#ifdef MS_WINDOWS
#define PyOS_strnicmp strnicmp
#define PyOS_stricmp stricmp
#else
#define PyOS_strnicmp PyOS_mystrnicmp
#define PyOS_stricmp PyOS_mystricmp
#endif
msg226308 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2014-09-03 09:20
Unfortunately they seem to be part of the stable ABI (#18603).
msg399286 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-08-09 19:14
This was fixed under Issue 41524.
History
Date User Action Args
2022-04-11 14:58:07adminsetgithub: 66526
2021-08-09 19:14:17iritkatrielsetstatus: open -> closed

superseder: PyOS_mystricmp advances pointers too far

nosy: + iritkatriel
messages: + msg399286
resolution: duplicate
stage: resolved
2014-10-14 16:06:23skrahsetnosy: - skrah
2014-09-03 09:20:49skrahsetmessages: + msg226308
2014-09-03 09:15:55kakkokosetmessages: + msg226307
2014-09-03 09:13:46skrahsetnosy: + skrah
messages: + msg226306
2014-09-03 09:08:39vstinnersetnosy: + vstinner
messages: + msg226305
2014-09-03 09:04:29kakkokocreate