diff -r 0b04e5689c33 Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c Wed Jul 15 22:12:33 2015 +0300 +++ b/Modules/cjkcodecs/multibytecodec.c Thu Jul 16 00:59:54 2015 +0200 @@ -1685,14 +1685,18 @@ static PyObject * { PyObject *pwrt; - pwrt = multibytecodec_encode(self->codec, &self->state, - self->pending, NULL, self->errors, - MBENC_FLUSH | MBENC_RESET); - /* some pending buffer can be truncated when UnicodeEncodeError is - * raised on 'strict' mode. but, 'reset' method is designed to - * reset the pending buffer or states so failed string sequence - * ought to be missed */ - Py_CLEAR(self->pending); + if (self->pending != NULL) { + pwrt = multibytecodec_encode(self->codec, &self->state, + self->pending, NULL, self->errors, + MBENC_FLUSH | MBENC_RESET); + /* some pending buffer can be truncated when UnicodeEncodeError is + * raised on 'strict' mode. but, 'reset' method is designed to + * reset the pending buffer or states so failed string sequence + * ought to be missed */ + Py_CLEAR(self->pending); + } + else + pwrt = PyBytes_FromStringAndSize("", 0); if (pwrt == NULL) return NULL;