8000 Convert unicode index to long, not int, in get_char_index by AdamWill · Pull Request #7768 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Convert unicode index to long, not int, in get_char_index #7768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Convert unicode index to long, not int, in get_char_index
There's an error in the `PyFT2Font.get_char_index()` method
added in 2d56ffeb . The type for the unicode index to be sent
to `FT_Get_Char_Index` is `FT_ULong` - an unsigned long - but
the `PyArg_ParseTuple` call that converts it from Python used
`I` in the format string, which converts a Python int to a C
unsigned int, not a C unsigned long. This doesn't seem to cause
a problem on little-endian arches, but it results in completely
incorrect conversion on big-endian arches, which in turn would
result in wrong glyphs, unfound glyphs, and even in an infinite
recursion in `UnicodeFonts._get_glyph`.

To get correct conversion we must use `k` not `I`, which is
the specifier for a C unsigned long.

Ref: https://docs.python.org/3/c-api/arg.html#numbers
  • Loading branch information
AdamWill committed Jan 9, 2017
commit c4c0b657ca7b55b99d87b045852227523a293848
2 changes: 1 addition & 1 deletion src/ft2font_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static PyObject *PyFT2Font_get_char_index(PyFT2Font *self, PyObject *args, PyObj
FT_UInt index;
FT_ULong ccode;

if (!PyArg_ParseTuple(args, "I:get_char_index", &ccode)) {
if (!PyArg_ParseTuple(args, "k:get_char_index", &ccode)) {
return NULL;
}

Expand Down
0