Skip to content

Commit d980a5f

Browse files
committed
Fix -Wsign-compare diagnostics
Cast the signed results of e.g., PyString_Size to size_t. In the event that the result is an error value somehow the negative value will almost certainly exceed the requested size and return with an error.
1 parent 8f2ad4f commit d980a5f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

fuseparts/_fusemodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,14 +687,14 @@ read_func(const char *path, char *buf, size_t s, off_t off)
687687
if(PyObject_CheckBuffer(v)) {
688688
PyObject_GetBuffer(v, &buffer, PyBUF_SIMPLE);
689689

690-
if(buffer.len <= s) {
690+
if((size_t)buffer.len <= s) {
691691
memcpy(buf, buffer.buf, buffer.len);
692692
ret = buffer.len;
693693
}
694694

695695
PyBuffer_Release(&buffer);
696696
} else if(PyBytes_Check(v)) {
697-
if(PyBytes_Size(v) > s)
697+
if((size_t)PyBytes_Size(v) > s)
698698
goto OUT_DECREF;
699699
memcpy(buf, PyBytes_AsString(v), PyBytes_Size(v));
700700
ret = PyBytes_Size(v);
@@ -948,7 +948,7 @@ getxattr_func(const char *path, const char *name, char *value, size_t size)
948948
/* If the size of the value buffer is too small to hold the result, errno
949949
* is set to ERANGE.
950950
*/
951-
if (PyString_Size(v) > size) {
951+
if ((size_t)PyString_Size(v) > size) {
952952
ret = -ERANGE;
953953
goto OUT_DECREF;
954954
}
@@ -984,7 +984,7 @@ listxattr_func(const char *path, char *list, size_t size)
984984
}
985985

986986
for (;;) {
987-
int ilen;
987+
size_t ilen;
988988

989989
w = PyIter_Next(iter);
990990
if (!w) {

0 commit comments

Comments
 (0)