Changed example code to avoid potential divide by zero

main
Sam Lantinga 2023-08-08 16:52:09 -07:00
parent 8a1afc9b10
commit 279ff8909f
1 changed files with 4 additions and 2 deletions

View File

@ -925,8 +925,10 @@ should be changed to:
```
size_t custom_read(void *ptr, size_t size, size_t nitems, SDL_RWops *stream)
{
size_t bytes = SDL_RWread(stream, ptr, size * nitems);
return (bytes / size);
if (size > 0 && nitems > 0) {
return SDL_RWread(stream, ptr, size * nitems) / size;
}
return 0;
}
```