Skip to content

Commit

Permalink
Fixed some issues found with static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 27, 2024
1 parent df025f7 commit 8333f7e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/test/SDL_test_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ static void SDLTest_PrintWindowFlag(char *text, size_t maxlen, SDL_WindowFlags f
SDL_snprintfcat(text, maxlen, "TRANSPARENT");
break;
default:
SDL_snprintfcat(text, maxlen, "0x%8.8x", flag);
SDL_snprintfcat(text, maxlen, "0x%16.16" SDL_PRIx64, flag);
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/thread/windows/SDL_sysmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ static SDL_Mutex *SDL_CreateMutex_cs(void)
#ifdef SDL_PLATFORM_WINRT
InitializeCriticalSectionEx(&mutex->cs, 2000, 0);
#else
InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
// This function always succeeds
(void)InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
#endif
}
return (SDL_Mutex *)mutex;
Expand Down
30 changes: 24 additions & 6 deletions src/video/SDL_blit_0.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,16 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX1) {
switch (surface->internal->map.info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit_1b[which];
if (which < SDL_arraysize(bitmap_blit_1b)) {
return bitmap_blit_1b[which];
}
break;

case SDL_COPY_COLORKEY:
return colorkey_blit_1b[which];
if (which < SDL_arraysize(colorkey_blit_1b)) {
return colorkey_blit_1b[which];
}
break;

case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit1btoNAlpha : (SDL_BlitFunc)NULL;
Expand All @@ -945,10 +951,16 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX2) {
switch (surface->internal->map.info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit_2b[which];
if (which < SDL_arraysize(bitmap_blit_2b)) {
return bitmap_blit_2b[which];
}
break;

case SDL_COPY_COLORKEY:
return colorkey_blit_2b[which];
if (which < SDL_arraysize(colorkey_blit_2b)) {
return colorkey_blit_2b[which];
}
break;

case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit2btoNAlpha : (SDL_BlitFunc)NULL;
Expand All @@ -962,10 +974,16 @@ SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface)
if (SDL_PIXELTYPE(surface->format) == SDL_PIXELTYPE_INDEX4) {
switch (surface->internal->map.info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return bitmap_blit_4b[which];
if (which < SDL_arraysize(bitmap_blit_4b)) {
return bitmap_blit_4b[which];
}
break;

case SDL_COPY_COLORKEY:
return colorkey_blit_4b[which];
if (which < SDL_arraysize(colorkey_blit_4b)) {
return colorkey_blit_4b[which];
}
break;

case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
return which >= 2 ? Blit4btoNAlpha : (SDL_BlitFunc)NULL;
Expand Down
10 changes: 8 additions & 2 deletions src/video/SDL_blit_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,16 @@ SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface)

switch (surface->internal->map.info.flags & ~SDL_COPY_RLE_MASK) {
case 0:
return one_blit[which];
if (which < SDL_arraysize(one_blit)) {
return one_blit[which];
}
break;

case SDL_COPY_COLORKEY:
return one_blitkey[which];
if (which < SDL_arraysize(one_blitkey)) {
return one_blitkey[which];
}
break;

case SDL_COPY_COLORKEY | SDL_COPY_BLEND: /* this is not super-robust but handles a specific case we found sdl12-compat. */
return (surface->internal->map.info.a == 255) ? one_blitkey[which] :
Expand Down
8 changes: 5 additions & 3 deletions test/checkkeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,12 @@ int main(int argc, char *argv[])
#endif

done:
for (i = 0; i < state->num_windows; ++i) {
SDLTest_TextWindowDestroy(windowstates[i].textwindow);
if (windowstates) {
for (i = 0; i < state->num_windows; ++i) {
SDLTest_TextWindowDestroy(windowstates[i].textwindow);
}
SDL_free(windowstates);
}
SDL_free(windowstates);
SDLTest_CleanupTextDrawing();
SDLTest_CommonQuit(state);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion test/testautomation_stdlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ static int stdlib_swprintf(void *arg)
const wchar_t *expected;
size_t size;

result = SDL_swprintf(text, sizeof(text), L"%s", "foo");
result = SDL_swprintf(text, SDL_arraysize(text), L"%s", "foo");
expected = L"foo";
SDLTest_AssertPass("Call to SDL_swprintf(\"%%s\", \"foo\")");
SDLTest_AssertCheck(SDL_wcscmp(text, expected) == 0, "Check text, expected: %S, got: %S", expected, text);
Expand Down

0 comments on commit 8333f7e

Please sign in to comment.