static analysis: Fixed several complaints from codechecker. There are still some pending Objective-C specific issues. Reference issue #4600.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
diff --git a/src/SDL.c b/src/SDL.c
index dfc4572..68a4f5d 100644
--- a/src/SDL.c
+++ b/src/SDL.c
@@ -316,6 +316,8 @@ SDL_InitSubSystem(Uint32 flags)
#endif
}
+ (void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
+
return (0);
quit_and_error:
diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c
index 07eb101..e49b550 100644
--- a/src/audio/SDL_wave.c
+++ b/src/audio/SDL_wave.c
@@ -685,7 +685,7 @@ MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
state.output.pos = 0;
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) {
return SDL_OutOfMemory();
}
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 2e88ee7..acf75ac 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -384,8 +384,6 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
/* Ignore relative motion when first positioning the mouse */
if (!mouse->has_position) {
- xrel = 0;
- yrel = 0;
mouse->x = x;
mouse->y = y;
mouse->has_position = SDL_TRUE;
diff --git a/src/hidapi/mac/hid.c b/src/hidapi/mac/hid.c
index a9a85b1..ec7ffaf 100644
--- a/src/hidapi/mac/hid.c
+++ b/src/hidapi/mac/hid.c
@@ -572,8 +572,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
if ((vendor_id == 0x0 && product_id == 0x0) ||
(vendor_id == dev_vid && product_id == dev_pid)) {
struct hid_device_info *tmp;
- size_t len;
-
+
/* VID/PID match. Create the record. */
tmp = (struct hid_device_info *)calloc(1, sizeof(struct hid_device_info));
if (cur_dev) {
@@ -590,7 +589,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
/* Fill out the record */
cur_dev->next = NULL;
- len = make_path(dev, cbuf, sizeof(cbuf));
+ make_path(dev, cbuf, sizeof(cbuf));
cur_dev->path = strdup(cbuf);
/* 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);
for (i = 0; i < num_devices; i++) {
char cbuf[BUF_LEN];
- size_t len;
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)) {
// Matched Paths. Open this Device.
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 */
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));
/* 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
return buffer (data), and delete the liked list item. */
struct input_report *rpt = dev->input_reports;
- size_t len = (length < rpt->len)? length: rpt->len;
- memcpy(data, rpt->data, len);
- dev->input_reports = rpt->next;
- free(rpt->data);
- free(rpt);
+ size_t len = 0;
+ if (rpt != NULL) {
+ len = (length < rpt->len)? length: rpt->len;
+ memcpy(data, rpt->data, len);
+ dev->input_reports = rpt->next;
+ free(rpt->data);
+ free(rpt);
+ }
return (int)len;
}
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 3f3482b..70e19ac 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1590,11 +1590,13 @@ SDL_JoystickUpdate(void)
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
if (joystick->attached) {
- /* This should always be true, but seeing a crash in the wild...? */
- if (joystick->driver) {
- joystick->driver->Update(joystick);
+ /* This driver should always be != NULL, but seeing a crash in the wild...? */
+ if (!joystick->driver) {
+ continue; /* nothing we can do, and other things use joystick->driver below here. */
}
+ joystick->driver->Update(joystick);
+
if (joystick->delayed_guide_button) {
SDL_GameControllerHandleDelayedGuideButton(joystick);
}
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 55d9a13..f54b3c3 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -227,7 +227,7 @@ HIDAPI_CleanupDeviceDriver(SDL_HIDAPI_Device *device)
}
/* Disconnect any joysticks */
- while (device->num_joysticks) {
+ while (device->num_joysticks && device->joysticks) {
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
}
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index c5f6834..30fee88 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -3145,10 +3145,11 @@ SDL_RenderDrawLinesF(SDL_Renderer * renderer,
num_vertices, indices, num_indices, size_indices,
1.0f, 1.0f);
- SDL_small_free(xy, isstack1);
- SDL_small_free(indices, isstack2);
}
+ SDL_small_free(xy, isstack1);
+ SDL_small_free(indices, isstack2);
+
} else if (renderer->scale.x != 1.0f || renderer->scale.y != 1.0f) {
retval = RenderDrawLinesWithRectsF(renderer, points, count);
} else {
diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c
index 0987f54..03b3e2f 100644
--- a/src/video/SDL_bmp.c
+++ b/src/video/SDL_bmp.c
@@ -394,6 +394,12 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
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 */
surface =
SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index c9fb476..924b3fd 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -530,7 +530,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
}
#endif
/* 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);
}
if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 3be9880..f2c7b8b 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -261,6 +261,7 @@ SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window * window, Uint32 * fo
SDL_TEXTUREACCESS_STREAMING,
window->w, window->h);
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;
}
@@ -1184,6 +1185,7 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
} else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
&fullscreen_mode,
&fullscreen_mode)) {
+ SDL_zerop(mode);
return SDL_SetError("Couldn't find display mode match");
}