10000 Fix the compiler warning a different way. · python/cpython@fc6920d · GitHub
[go: up one dir, main page]

Skip to content

Commit fc6920d

Browse files
Fix the compiler warning a different way.
1 parent d034ec5 commit fc6920d

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Include/internal/pycore_moduleobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern PyObject * _PyModule_GetFilenameObject(PyObject *);
5151
extern Py_ssize_t _PyModule_GetFilenameUTF8(
5252
PyObject *module,
5353
char *buffer,
54-
size_t maxlen);
54+
Py_ssize_t maxlen);
5555

5656
PyObject* _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress);
5757
PyObject* _Py_module_getattro(PyObject *m, PyObject *name);

Objects/moduleobject.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,11 @@ PyModule_GetFilename(PyObject *m)
668668
}
669669

670670
Py_ssize_t
671-
_PyModule_GetFilenameUTF8(PyObject *mod, char *buffer, size_t maxlen)
671+
_PyModule_GetFilenameUTF8(PyObject *mod, char *buffer, Py_ssize_t maxlen)
672672
{
673673
// We "return" an empty string for an invalid module
674674
// and for a missing, empty, or invalid filename.
675+
assert(maxlen >= 0);
675676
Py_ssize_t size = -1;
676677
PyObject *filenameobj = _PyModule_GetFilenameObject(mod);
677678
if (filenameobj == NULL) {
@@ -684,7 +685,8 @@ _PyModule_GetFilenameUTF8(PyObject *mod, char *buffer, size_t maxlen)
684685
}
685686
else {
686687
const char *filename = PyUnicode_AsUTF8AndSize(filenameobj, &size);
687-
if (size > PY_SIZE_MAX || (size_t)size > maxlen) {
688+
assert(size >= 0);
689+
if (size > maxlen) {
688690
size = -1;
689691
PyErr_SetString(PyExc_ValueError, "__file__ too long");
690692
}

0 commit comments

Comments
 (0)
0