@@ -316,20 +316,27 @@ typedef enum {
316316static _Py_error_handler
317317get_error_handler (const char * errors )
318318{
319- if (errors == NULL || strcmp (errors , "strict" ) == 0 )
319+ if (errors == NULL || strcmp (errors , "strict" ) == 0 ) {
320320 return _Py_ERROR_STRICT ;
321- if (strcmp (errors , "surrogateescape" ) == 0 )
321+ }
322+ if (strcmp (errors , "surrogateescape" ) == 0 ) {
322323 return _Py_ERROR_SURROGATEESCAPE ;
323- if (strcmp (errors , "replace" ) == 0 )
324+ }
325+ if (strcmp (errors , "replace" ) == 0 ) {
324326 return _Py_ERROR_REPLACE ;
325- if (strcmp (errors , "ignore" ) == 0 )
327+ }
328+ if (strcmp (errors , "ignore" ) == 0 ) {
326329 return _Py_ERROR_IGNORE ;
327- if (strcmp (errors , "backslashreplace" ) == 0 )
330+ }
331+ if (strcmp (errors , "backslashreplace" ) == 0 ) {
328332 return _Py_ERROR_BACKSLASHREPLACE ;
329- if (strcmp (errors , "surrogatepass" ) == 0 )
333+ }
334+ if (strcmp (errors , "surrogatepass" ) == 0 ) {
330335 return _Py_ERROR_SURROGATEPASS ;
331- if (strcmp (errors , "xmlcharrefreplace" ) == 0 )
336+ }
337+ if (strcmp (errors , "xmlcharrefreplace" ) == 0 ) {
332338 return _Py_ERROR_XMLCHARREFREPLACE ;
339+ }
333340 return _Py_ERROR_OTHER ;
334341}
335342
@@ -5636,36 +5643,45 @@ _PyUnicode_EncodeUTF16(PyObject *str,
56365643 if (kind == PyUnicode_4BYTE_KIND ) {
56375644 const Py_UCS4 * in = (const Py_UCS4 * )data ;
56385645 const Py_UCS4 * end = in + len ;
5639- while (in < end )
5640- if (* in ++ >= 0x10000 )
5646+ while (in < end ) {
5647+ if (* in ++ >= 0x10000 ) {
56415648 pairs ++ ;
5649+ }
5650+ }
56425651 }
5643- if (len > PY_SSIZE_T_MAX / 2 - pairs - (byteorder == 0 ))
5652+ if (len > PY_SSIZE_T_MAX / 2 - pairs - (byteorder == 0 )) {
56445653 return PyErr_NoMemory ();
5654+ }
56455655 nsize = len + pairs + (byteorder == 0 );
56465656 v = PyBytes_FromStringAndSize (NULL , nsize * 2 );
5647- if (v == NULL )
5657+ if (v == NULL ) {
56485658 return NULL ;
5659+ }
56495660
56505661 /* output buffer is 2-bytes aligned */
56515662 assert (_Py_IS_ALIGNED (PyBytes_AS_STRING (v ), 2 ));
56525663 out = (unsigned short * )PyBytes_AS_STRING (v );
5653- if (byteorder == 0 )
5664+ if (byteorder == 0 ) {
56545665 * out ++ = 0xFEFF ;
5655- if (len == 0 )
5666+ }
5667+ if (len == 0 ) {
56565668 goto done ;
5669+ }
56575670
56585671 if (kind == PyUnicode_1BYTE_KIND ) {
56595672 ucs1lib_utf16_encode ((const Py_UCS1 * )data , len , & out , native_ordering );
56605673 goto done ;
56615674 }
56625675
5663- if (byteorder < 0 )
5676+ if (byteorder < 0 ) {
56645677 encoding = "utf-16-le" ;
5665- else if (byteorder > 0 )
5678+ }
5679+ else if (byteorder > 0 ) {
56665680 encoding = "utf-16-be" ;
5667- else
5681+ }
5682+ else {
56685683 encoding = "utf-16" ;
5684+ }
56695685
56705686 pos = 0 ;
56715687 while (pos < len ) {
0 commit comments