static analysis: Fixed several complaints from codechecker.

There are still some pending Objective-C specific issues.

Reference issue #4600.
This commit is contained in:
Ryan C. Gordon 2022-03-24 11:00:43 -04:00
parent eadc064e2c
commit 4fe7b2cbd1
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
10 changed files with 33 additions and 20 deletions

View File

@ -316,6 +316,8 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
(void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
return (0); return (0);
quit_and_error: quit_and_error:

View File

@ -685,7 +685,7 @@ MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
state.output.pos = 0; state.output.pos = 0;
state.output.size = outputsize / sizeof(Sint16); state.output.size = outputsize / sizeof(Sint16);
state.output.data = (Sint16 *)SDL_malloc(outputsize); state.output.data = (Sint16 *)SDL_calloc(1, outputsize);
if (state.output.data == NULL) { if (state.output.data == NULL) {
return SDL_OutOfMemory(); return SDL_OutOfMemory();
} }

View File

@ -384,8 +384,6 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
/* Ignore relative motion when first positioning the mouse */ /* Ignore relative motion when first positioning the mouse */
if (!mouse->has_position) { if (!mouse->has_position) {
xrel = 0;
yrel = 0;
mouse->x = x; mouse->x = x;
mouse->y = y; mouse->y = y;
mouse->has_position = SDL_TRUE; mouse->has_position = SDL_TRUE;

View File

@ -572,7 +572,6 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
if ((vendor_id == 0x0 && product_id == 0x0) || if ((vendor_id == 0x0 && product_id == 0x0) ||
(vendor_id == dev_vid && product_id == dev_pid)) { (vendor_id == dev_vid && product_id == dev_pid)) {
struct hid_device_info *tmp; struct hid_device_info *tmp;
size_t len;
/* VID/PID match. Create the record. */ /* VID/PID match. Create the record. */
tmp = (struct hid_device_info *)calloc(1, sizeof(struct hid_device_info)); tmp = (struct hid_device_info *)calloc(1, sizeof(struct hid_device_info));
@ -590,7 +589,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Fill out the record */ /* Fill out the record */
cur_dev->next = NULL; cur_dev->next = NULL;
len = make_path(dev, cbuf, sizeof(cbuf)); make_path(dev, cbuf, sizeof(cbuf));
cur_dev->path = strdup(cbuf); cur_dev->path = strdup(cbuf);
/* Serial Number */ /* Serial Number */
@ -817,10 +816,9 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
CFSetGetValues(device_set, (const void **) device_array); CFSetGetValues(device_set, (const void **) device_array);
for (i = 0; i < num_devices; i++) { for (i = 0; i < num_devices; i++) {
char cbuf[BUF_LEN]; char cbuf[BUF_LEN];
size_t len;
IOHIDDeviceRef os_dev = device_array[i]; IOHIDDeviceRef os_dev = device_array[i];
len = make_path(os_dev, cbuf, sizeof(cbuf)); make_path(os_dev, cbuf, sizeof(cbuf));
if (!strcmp(cbuf, path)) { if (!strcmp(cbuf, path)) {
// Matched Paths. Open this Device. // Matched Paths. Open this Device.
IOReturn ret = IOHIDDeviceOpen(os_dev, kIOHIDOptionsTypeNone); IOReturn ret = IOHIDDeviceOpen(os_dev, kIOHIDOptionsTypeNone);
@ -833,6 +831,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
/* Create the buffers for receiving data */ /* Create the buffers for receiving data */
dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev); dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev);
SDL_assert(dev->max_input_report_len > 0);
dev->input_report_buf = (uint8_t *)calloc(dev->max_input_report_len, sizeof(uint8_t)); dev->input_report_buf = (uint8_t *)calloc(dev->max_input_report_len, sizeof(uint8_t));
/* Create the Run Loop Mode for this device. /* Create the Run Loop Mode for this device.
@ -936,11 +935,14 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length)
/* Copy the data out of the linked list item (rpt) into the /* Copy the data out of the linked list item (rpt) into the
return buffer (data), and delete the liked list item. */ return buffer (data), and delete the liked list item. */
struct input_report *rpt = dev->input_reports; struct input_report *rpt = dev->input_reports;
size_t len = (length < rpt->len)? length: rpt->len; size_t len = 0;
if (rpt != NULL) {
len = (length < rpt->len)? length: rpt->len;
memcpy(data, rpt->data, len); memcpy(data, rpt->data, len);
dev->input_reports = rpt->next; dev->input_reports = rpt->next;
free(rpt->data); free(rpt->data);
free(rpt); free(rpt);
}
return (int)len; return (int)len;
} }

View File

@ -1590,11 +1590,13 @@ SDL_JoystickUpdate(void)
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) { for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
if (joystick->attached) { if (joystick->attached) {
/* This should always be true, but seeing a crash in the wild...? */ /* This driver should always be != NULL, but seeing a crash in the wild...? */
if (joystick->driver) { if (!joystick->driver) {
joystick->driver->Update(joystick); continue; /* nothing we can do, and other things use joystick->driver below here. */
} }
joystick->driver->Update(joystick);
if (joystick->delayed_guide_button) { if (joystick->delayed_guide_button) {
SDL_GameControllerHandleDelayedGuideButton(joystick); SDL_GameControllerHandleDelayedGuideButton(joystick);
} }

View File

@ -227,7 +227,7 @@ HIDAPI_CleanupDeviceDriver(SDL_HIDAPI_Device *device)
} }
/* Disconnect any joysticks */ /* Disconnect any joysticks */
while (device->num_joysticks) { while (device->num_joysticks && device->joysticks) {
HIDAPI_JoystickDisconnected(device, device->joysticks[0]); HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
} }

View File

@ -3145,9 +3145,10 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
num_vertices, indices, num_indices, size_indices, num_vertices, indices, num_indices, size_indices,
1.0f, 1.0f); 1.0f, 1.0f);
}
SDL_small_free(xy, isstack1); SDL_small_free(xy, isstack1);
SDL_small_free(indices, isstack2); SDL_small_free(indices, isstack2);
}
} else if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) { } else if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
retval = RenderDrawLinesWithRectsF(renderer, points, count); retval = RenderDrawLinesWithRectsF(renderer, points, count);

View File

@ -394,6 +394,12 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
break; break;
} }
if (biBitCount >= 32) { /* we shift biClrUsed by this value later. */
SDL_SetError("Unsupported or incorrect biBitCount field");
was_error = SDL_TRUE;
goto done;
}
/* Create a compatible surface, note that the colors are RGB ordered */ /* Create a compatible surface, note that the colors are RGB ordered */
surface = surface =
SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask, SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,

View File

@ -530,7 +530,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
} }
#endif #endif
/* Try the implementation-specific eglGetDisplay even if eglGetPlatformDisplay fails */ /* Try the implementation-specific eglGetDisplay even if eglGetPlatformDisplay fails */
if (_this->egl_data->egl_display == EGL_NO_DISPLAY) { if ((_this->egl_data->egl_display == EGL_NO_DISPLAY) && (_this->egl_data->eglGetDisplay != NULL)) {
_this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display); _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
} }
if (_this->egl_data->egl_display == EGL_NO_DISPLAY) { if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {

View File

@ -261,6 +261,7 @@ SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window * window, Uint32 * fo
SDL_TEXTUREACCESS_STREAMING, SDL_TEXTUREACCESS_STREAMING,
window->w, window->h); window->w, window->h);
if (!data->texture) { if (!data->texture) {
/* codechecker_false_positive [Malloc] Static analyzer doesn't realize allocated `data` is saved to SDL_WINDOWTEXTUREDATA and not leaked here. */
return -1; return -1;
} }
@ -1184,6 +1185,7 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
} else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window), } else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
&fullscreen_mode, &fullscreen_mode,
&fullscreen_mode)) { &fullscreen_mode)) {
SDL_zerop(mode);
return SDL_SetError("Couldn't find display mode match"); return SDL_SetError("Couldn't find display mode match");
} }