diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index c8331c81eb..c9868efd46 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -958,15 +958,14 @@ int win1252_to_utf8(utf8string dst, const char *src, size_t maxBufferLength) if (srcLength > bufferCount) { bufferCount = srcLength + 4; heapBuffer = malloc(bufferCount * sizeof(utf16)); + assert(heapBuffer != NULL); intermediateBuffer = heapBuffer; } } MultiByteToWideChar(CP_ACP, 0, src, -1, intermediateBuffer, bufferCount); int result = WideCharToMultiByte(CP_UTF8, 0, intermediateBuffer, -1, dst, maxBufferLength, NULL, NULL); - if (heapBuffer != NULL) { - free(heapBuffer); - } + free(heapBuffer); #else //log_warning("converting %s of size %d", src, srcLength); char *buffer_conv = strndup(src, srcLength); diff --git a/src/platform/windows.c b/src/platform/windows.c index b594395bab..2f57d3b2c7 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -195,10 +195,10 @@ bool platform_directory_delete(const utf8 *path) wchar_t *wPath = utf8_to_widechar(path); wcsncpy(pszFrom, wPath, MAX_PATH); - free(wPath); // Needs to be double-null terminated for some weird reason pszFrom[wcslen(wPath) + 1] = 0; + free(wPath); SHFILEOPSTRUCTW fileop; fileop.hwnd = NULL; // no status display @@ -370,8 +370,10 @@ int platform_enumerate_directories_begin(const utf8 *directory) wchar_t *wDirectory = utf8_to_widechar(directory); - if (wcslen(wDirectory) + 3 >= MAX_PATH) + if (wcslen(wDirectory) + 3 >= MAX_PATH) { + free(wDirectory); return INVALID_HANDLE; + } for (i = 0; i < countof(_enumerateFileInfoList); i++) { enumFileInfo = &_enumerateFileInfoList[i]; @@ -634,7 +636,7 @@ bool platform_open_common_file_dialog(utf8 *outFilename, file_dialog_desc *desc) openFileName.lpstrFilter = wcFilter; // Open dialog - BOOL result; + BOOL result = false; DWORD commonFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR; if (desc->type == FD_OPEN) { openFileName.Flags = commonFlags | OFN_NONETWORKBUTTON | OFN_FILEMUSTEXIST; diff --git a/src/ride/ride.c b/src/ride/ride.c index 6cad6750a1..f895f4f6d0 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -1695,9 +1695,12 @@ int ride_modify(rct_xy_element *input) mapElement = *input; rideIndex = mapElement.element->properties.track.ride_index; ride = get_ride(rideIndex); + if (ride == NULL) { + return 0; + } rideType = get_ride_entry_by_ride(ride); - if ((ride == NULL) || (rideType == NULL) || !ride_check_if_construction_allowed(ride)) + if ((rideType == NULL) || !ride_check_if_construction_allowed(ride)) return 0; if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE) { diff --git a/src/world/duck.c b/src/world/duck.c index 852ef6da40..6218339b59 100644 --- a/src/world/duck.c +++ b/src/world/duck.c @@ -277,7 +277,7 @@ static void duck_update_fly_away(rct_duck *duck) return; } - int z = z = min(duck->z + 2, 496); + int z = min(duck->z + 2, 496); sprite_move(x, y, z, (rct_sprite*)duck); duck_invalidate(duck); }