[Python-checkins] cjkcodecs: Fix compiler warning (GH-10651)

Victor Stinner webhook-mailer at python.org
Thu Nov 22 04:25:50 EST 2018

commit: cdbcb773f5db24e23fa90e644ec620d54bd08127
branch: master
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-11-22T10:25:46+01:00

cjkcodecs: Fix compiler warning (GH-10651)

Fixed the following compiler warning in multibytecodec.c:

    warning C4244: '=': conversion from 'Py_ssize_t'
    to 'unsigned char', possible loss of data

Cast Py_ssize_t to unsigned char: the maximum value is checked
on the previous line.

M Modules/cjkcodecs/multibytecodec.c

diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 9409456c0d27..8a0ac870f15e 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -923,8 +923,8 @@ _multibytecodec_MultibyteIncrementalEncoder_getstate_impl(MultibyteIncrementalEn
             PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
             return NULL;
-        statebytes[0] = pendingsize;
-        memcpy(statebytes+1, pendingbuffer, pendingsize);
+        statebytes[0] = (unsigned char)pendingsize;
+        memcpy(statebytes + 1, pendingbuffer, pendingsize);
         statesize = 1 + pendingsize;
     } else {
         statebytes[0] = 0;

More information about the Python-checkins mailing list