File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3165,7 +3165,6 @@ makeuniversal(XMLParserObject* self, const char* string)
31653165 necessary */
31663166
31673167 PyObject * tag ;
3168- char * p ;
31693168 Py_ssize_t i ;
31703169
31713170 /* look for namespace separator */
@@ -3174,22 +3173,28 @@ makeuniversal(XMLParserObject* self, const char* string)
31743173 break ;
31753174 if (i != size ) {
31763175 /* convert to universal name */
3177- tag = PyBytes_FromStringAndSize ( NULL , size + 1 );
3178- if (tag == NULL ) {
3176+ PyBytesWriter * writer = PyBytesWriter_Create ( 1 + size );
3177+ if (writer == NULL ) {
31793178 Py_DECREF (key );
31803179 return NULL ;
31813180 }
3182- p = PyBytes_AS_STRING ( tag );
3181+ char * p = PyBytesWriter_GetData ( writer );
31833182 p [0 ] = '{' ;
31843183 memcpy (p + 1 , string , size );
31853184 size ++ ;
3185+
3186+ tag = PyBytesWriter_Finish (writer );
3187+ if (tag == NULL ) {
3188+ Py_DECREF (key );
3189+ return NULL ;
3190+ }
31863191 } else {
31873192 /* plain name; use key as tag */
31883193 tag = Py_NewRef (key );
31893194 }
31903195
31913196 /* decode universal name */
3192- p = PyBytes_AS_STRING (tag );
3197+ const char * p = PyBytes_AS_STRING (tag );
31933198 value = PyUnicode_DecodeUTF8 (p , size , "strict" );
31943199 Py_DECREF (tag );
31953200 if (!value ) {
You can’t perform that action at this time.
0 commit comments