mirror of
				https://github.com/python/cpython.git
				synced 2025-11-01 06:01:29 +00:00 
			
		
		
		
	PyUnicode_AsUnicodeCopy() now checks if PyUnicode_AsUnicode() failed
This commit is contained in:
		
							parent
							
								
									d9c0631d77
								
							
						
					
					
						commit
						577db2c9f0
					
				
					 1 changed files with 5 additions and 2 deletions
				
			
		|  | @ -13775,13 +13775,16 @@ Py_UNICODE* | |||
| PyUnicode_AsUnicodeCopy(PyObject *object) | ||||
| { | ||||
|     PyUnicodeObject *unicode = (PyUnicodeObject *)object; | ||||
|     Py_UNICODE *copy; | ||||
|     Py_UNICODE *u, *copy; | ||||
|     Py_ssize_t size; | ||||
| 
 | ||||
|     if (!PyUnicode_Check(unicode)) { | ||||
|         PyErr_BadArgument(); | ||||
|         return NULL; | ||||
|     } | ||||
|     u = PyUnicode_AsUnicode(object); | ||||
|     if (u == NULL) | ||||
|         return NULL; | ||||
|     /* Ensure we won't overflow the size. */ | ||||
|     if (PyUnicode_GET_SIZE(unicode) > ((PY_SSIZE_T_MAX / sizeof(Py_UNICODE)) - 1)) { | ||||
|         PyErr_NoMemory(); | ||||
|  | @ -13794,7 +13797,7 @@ PyUnicode_AsUnicodeCopy(PyObject *object) | |||
|         PyErr_NoMemory(); | ||||
|         return NULL; | ||||
|     } | ||||
|     memcpy(copy, PyUnicode_AS_UNICODE(unicode), size); | ||||
|     memcpy(copy, u, size); | ||||
|     return copy; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner