@@ -2157,6 +2157,8 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
2157
2157
#define FBLITS_ERR_CACHE_RLE_NOT_SUPPORTED 16
2158
2158
#define FBLITS_ERR_FLAG_NOT_SUPPORTED 17
2159
2159
#define FBLITS_ERR_NO_MEMORY 18
2160
+ #define FBLITS_ERR_INVALID_SEQUENCE_LENGTH 19
2161
+ #define FBLITS_ERR_INVALID_DESTINATION 20
2160
2162
2161
2163
int
2162
2164
_surf_fblits_item_check_and_blit (pgSurfaceObject * self , PyObject * item ,
@@ -2255,20 +2257,10 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2255
2257
return FBLITS_ERR_CACHE_RLE_NOT_SUPPORTED ;
2256
2258
}
2257
2259
2258
- /* manage destinations memory allocation or reallocation */
2260
+ /* manage destinations memory */
2259
2261
Py_ssize_t new_size = PyList_GET_SIZE (pos_list );
2260
- if (destinations -> sequence == NULL ) {
2261
- destinations -> sequence =
2262
- (CachedBlitDest * )malloc (new_size * sizeof (CachedBlitDest ));
2263
- destinations -> size = destinations -> alloc_size = new_size ;
2264
- if (!destinations -> sequence ) {
2265
- return FBLITS_ERR_NO_MEMORY ;
2266
- }
2267
- }
2268
- else if (new_size > 0 && new_size <= destinations -> alloc_size ) {
2269
- destinations -> size = new_size ;
2270
- }
2271
- else if (new_size > destinations -> alloc_size ) {
2262
+ if (new_size > destinations -> alloc_size ) {
2263
+ /* no realloc as we don't care about the previous destinations */
2272
2264
destinations -> sequence = (CachedBlitDest * )realloc (
2273
2265
destinations -> sequence , new_size * sizeof (CachedBlitDest ));
2274
2266
@@ -2277,8 +2269,13 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2277
2269
2278
2270
destinations -> size = destinations -> alloc_size = new_size ;
2279
2271
}
2272
+ else if (new_size > 0 && new_size <= destinations -> alloc_size ) {
2273
+ destinations -> size = new_size ;
2274
+ }
2280
2275
else {
2281
- return FBLITS_ERR_INCORRECT_ARGS_NUM ;
2276
+ if (new_size == 0 )
2277
+ return 0 ;
2278
+ return FBLITS_ERR_INVALID_SEQUENCE_LENGTH ;
2282
2279
}
2283
2280
2284
2281
/* load destinations */
@@ -2294,7 +2291,7 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2294
2291
2295
2292
if (!pg_IntFromObj (PyTuple_GET_ITEM (tup , 0 ), & x ) ||
2296
2293
!pg_IntFromObj (PyTuple_GET_ITEM (tup , 1 ), & y )) {
2297
- return FBLITS_ERR_INCORRECT_ARGS_NUM ;
2294
+ return FBLITS_ERR_INVALID_DESTINATION ;
2298
2295
}
2299
2296
2300
2297
if (x < - src -> w || x > dst -> w || y < - src -> h || y > dst -> h )
@@ -2367,6 +2364,9 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
2367
2364
pgSurface_Unprep (self );
2368
2365
pgSurface_Unprep ((pgSurfaceObject * )src_surf );
2369
2366
2367
+ if (error == -1 )
2368
+ error = BLITS_ERR_BLIT_FAIL ;
2369
+
2370
2370
return error ;
2371
2371
}
2372
2372
@@ -2518,6 +2518,12 @@ surf_fblits(pgSurfaceObject *self, PyObject *const *args, Py_ssize_t nargs)
2518
2518
"supported for this operation" );
2519
2519
case FBLITS_ERR_NO_MEMORY :
2520
2520
return RAISE (PyExc_MemoryError , "No memory available" );
2521
+ case FBLITS_ERR_INVALID_SEQUENCE_LENGTH :
2522
+ return RAISE (PyExc_ValueError ,
2523
+ "Invalid sequence length for cached blit" );
2524
+ case FBLITS_ERR_INVALID_DESTINATION :
2525
+ return RAISE (PyExc_TypeError ,
2526
+ "Invalid destination position for cached blit" );
2521
2527
}
2522
2528
return RAISE (PyExc_TypeError , "Unknown error" );
2523
2529
}
0 commit comments