@@ -2147,6 +2147,8 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
21472147#define FBLITS_ERR_CACHE_RLE_NOT_SUPPORTED 16
21482148#define FBLITS_ERR_FLAG_NOT_SUPPORTED 17
21492149#define FBLITS_ERR_NO_MEMORY 18
2150+ #define FBLITS_ERR_INVALID_SEQUENCE_LENGTH 19
2151+ #define FBLITS_ERR_INVALID_DESTINATION 20
21502152
21512153int
21522154_surf_fblits_item_check_and_blit (pgSurfaceObject * self , PyObject * item ,
@@ -2245,20 +2247,10 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22452247 return FBLITS_ERR_CACHE_RLE_NOT_SUPPORTED ;
22462248 }
22472249
2248- /* manage destinations memory allocation or reallocation */
2250+ /* manage destinations memory */
22492251 Py_ssize_t new_size = PyList_GET_SIZE (pos_list );
2250- if (destinations -> sequence == NULL ) {
2251- destinations -> sequence =
2252- (CachedBlitDest * )malloc (new_size * sizeof (CachedBlitDest ));
2253- destinations -> size = destinations -> alloc_size = new_size ;
2254- if (!destinations -> sequence ) {
2255- return FBLITS_ERR_NO_MEMORY ;
2256- }
2257- }
2258- else if (new_size > 0 && new_size <= destinations -> alloc_size ) {
2259- destinations -> size = new_size ;
2260- }
2261- else if (new_size > destinations -> alloc_size ) {
2252+ if (new_size > destinations -> alloc_size ) {
2253+ /* no realloc as we don't care about the previous destinations */
22622254 destinations -> sequence = (CachedBlitDest * )realloc (
22632255 destinations -> sequence , new_size * sizeof (CachedBlitDest ));
22642256
@@ -2267,8 +2259,13 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22672259
22682260 destinations -> size = destinations -> alloc_size = new_size ;
22692261 }
2262+ else if (new_size > 0 && new_size <= destinations -> alloc_size ) {
2263+ destinations -> size = new_size ;
2264+ }
22702265 else {
2271- return FBLITS_ERR_INCORRECT_ARGS_NUM ;
2266+ if (new_size == 0 )
2267+ return 0 ;
2268+ return FBLITS_ERR_INVALID_SEQUENCE_LENGTH ;
22722269 }
22732270
22742271 /* load destinations */
@@ -2284,7 +2281,7 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22842281
22852282 if (!pg_IntFromObj (PyTuple_GET_ITEM (tup , 0 ), & x ) ||
22862283 !pg_IntFromObj (PyTuple_GET_ITEM (tup , 1 ), & y )) {
2287- return FBLITS_ERR_INCORRECT_ARGS_NUM ;
2284+ return FBLITS_ERR_INVALID_DESTINATION ;
22882285 }
22892286
22902287 if (x < - src -> w || x > dst -> w || y < - src -> h || y > dst -> h )
@@ -2357,6 +2354,9 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
23572354 pgSurface_Unprep (self );
23582355 pgSurface_Unprep ((pgSurfaceObject * )src_surf );
23592356
2357+ if (error == -1 )
2358+ error = BLITS_ERR_BLIT_FAIL ;
2359+
23602360 return error ;
23612361}
23622362
@@ -2508,6 +2508,12 @@ surf_fblits(pgSurfaceObject *self, PyObject *const *args, Py_ssize_t nargs)
25082508 "supported for this operation" );
25092509 case FBLITS_ERR_NO_MEMORY :
25102510 return RAISE (PyExc_MemoryError , "No memory available" );
2511+ case FBLITS_ERR_INVALID_SEQUENCE_LENGTH :
2512+ return RAISE (PyExc_ValueError ,
2513+ "Invalid sequence length for cached blit" );
2514+ case FBLITS_ERR_INVALID_DESTINATION :
2515+ return RAISE (PyExc_TypeError ,
2516+ "Invalid destination position for cached blit" );
25112517 }
25122518 return RAISE (PyExc_TypeError , "Unknown error" );
25132519}
0 commit comments