mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-22 06:23:04 +01:00
Plug memory leaks, check memory accesses
This commit is contained in:
@@ -940,6 +940,7 @@ void widget_invalidate(rct_window *w, int widgetIndex)
|
||||
{
|
||||
rct_widget* widget;
|
||||
|
||||
assert(w != NULL);
|
||||
widget = &w->widgets[widgetIndex];
|
||||
if (widget->left == -2)
|
||||
return;
|
||||
@@ -1032,6 +1033,7 @@ void window_update_scroll_widgets(rct_window *w)
|
||||
|
||||
widgetIndex = 0;
|
||||
scrollIndex = 0;
|
||||
assert(w != NULL);
|
||||
for (widget = w->widgets; widget->type != WWT_LAST; widget++, widgetIndex++) {
|
||||
if (widget->type != WWT_SCROLL)
|
||||
continue;
|
||||
@@ -1073,6 +1075,7 @@ int window_get_scroll_data_index(rct_window *w, int widget_index)
|
||||
int i, result;
|
||||
|
||||
result = 0;
|
||||
assert(w != NULL);
|
||||
for (i = 0; i < widget_index; i++) {
|
||||
if (w->widgets[i].type == WWT_SCROLL)
|
||||
result++;
|
||||
@@ -1251,6 +1254,7 @@ void window_scroll_to_viewport(rct_window *w)
|
||||
{
|
||||
int x, y, z;
|
||||
rct_window *mainWindow;
|
||||
assert(w != NULL);
|
||||
// In original checked to make sure x and y were not -1 as well.
|
||||
if (w->viewport == NULL || w->viewport_focus_coordinates.y == -1)
|
||||
return;
|
||||
@@ -1287,6 +1291,7 @@ void window_scroll_to_location(rct_window *w, int x, int y, int z)
|
||||
.z = z
|
||||
};
|
||||
|
||||
assert(w != NULL);
|
||||
if (w->viewport) {
|
||||
sint16 height = map_element_height(x, y);
|
||||
if (z < height - 16) {
|
||||
|
||||
@@ -178,7 +178,7 @@ static void openrct2_set_exe_path()
|
||||
if (bytesRead == -1) {
|
||||
log_fatal("failed to read /proc/self/exe");
|
||||
}
|
||||
exePath[bytesRead] = '\0';
|
||||
exePath[bytesRead - 1] = '\0';
|
||||
log_verbose("######################################## Setting exe path to %s", exePath);
|
||||
char *exeDelimiter = strrchr(exePath, platform_get_path_separator());
|
||||
if (exeDelimiter == NULL)
|
||||
|
||||
@@ -6586,6 +6586,7 @@ static int peep_interact_with_shop(rct_peep* peep, sint16 x, sint16 y, rct_map_e
|
||||
|
||||
/* rct2: 0x0069524E */
|
||||
static int peep_move_one_tile(uint8 direction, rct_peep* peep){
|
||||
assert(direction <= 7);
|
||||
sint16 x = peep->next_x;
|
||||
sint16 y = peep->next_y;
|
||||
x += TileDirectionDelta[direction].x;
|
||||
|
||||
@@ -46,10 +46,12 @@ bool platform_check_steam_overlay_attached() {
|
||||
|
||||
while (pl != NULL) {
|
||||
if (strstr(pl->path, "gameoverlayrenderer.so") != NULL) {
|
||||
dlclose(processHandle);
|
||||
return true;
|
||||
}
|
||||
pl = pl->next;
|
||||
}
|
||||
dlclose(processHandle);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ char platform_get_path_separator()
|
||||
bool platform_file_exists(const utf8 *path)
|
||||
{
|
||||
wchar_t *wPath = utf8_to_widechar(path);
|
||||
int len = min(MAX_PATH, utf8_length(path));
|
||||
int len = min(MAX_PATH - 1, utf8_length(path));
|
||||
char buffer[MAX_PATH];
|
||||
wcstombs(buffer, wPath, len);
|
||||
buffer[len] = '\0';
|
||||
@@ -108,7 +108,7 @@ bool platform_file_exists(const utf8 *path)
|
||||
bool platform_directory_exists(const utf8 *path)
|
||||
{
|
||||
wchar_t *wPath = utf8_to_widechar(path);
|
||||
int len = min(MAX_PATH, utf8_length(path));
|
||||
int len = min(MAX_PATH - 1, utf8_length(path));
|
||||
char buffer[MAX_PATH];
|
||||
wcstombs(buffer, wPath, len);
|
||||
buffer[len] = '\0';
|
||||
@@ -126,7 +126,7 @@ bool platform_directory_exists(const utf8 *path)
|
||||
bool platform_original_game_data_exists(const utf8 *path)
|
||||
{
|
||||
wchar_t *wPath = utf8_to_widechar(path);
|
||||
int len = min(MAX_PATH, utf8_length(path));
|
||||
int len = min(MAX_PATH - 1, utf8_length(path));
|
||||
char buffer[MAX_PATH];
|
||||
wcstombs(buffer, wPath, len);
|
||||
buffer[len] = '\0';
|
||||
@@ -530,7 +530,7 @@ wchar_t *regular_to_wchar(const char* src)
|
||||
/**
|
||||
* Default directory fallback is:
|
||||
* - (command line argument)
|
||||
* - $XDG_CONFIG_HOME/.config/OpenRCT2
|
||||
* - $XDG_CONFIG_HOME/OpenRCT2
|
||||
* - /home/[uid]/.config/OpenRCT2
|
||||
*/
|
||||
void platform_resolve_user_data_path()
|
||||
@@ -592,8 +592,8 @@ void platform_get_user_directory(utf8 *outPath, const utf8 *subDirectory)
|
||||
safe_strncpy(buffer, _userDataDirectoryPath, sizeof(buffer));
|
||||
if (subDirectory != NULL && subDirectory[0] != 0) {
|
||||
log_verbose("adding subDirectory '%s'", subDirectory);
|
||||
strcat(buffer, subDirectory);
|
||||
strcat(buffer, separator);
|
||||
strncat(buffer, subDirectory, MAX_PATH);
|
||||
strncat(buffer, separator, MAX_PATH);
|
||||
}
|
||||
int len = strnlen(buffer, MAX_PATH);
|
||||
wchar_t *w_buffer = regular_to_wchar(buffer);
|
||||
|
||||
@@ -359,8 +359,8 @@ void scenario_begin()
|
||||
format_string(parkName, RCT2_GLOBAL(RCT2_ADDRESS_PARK_NAME, rct_string_id), (void*)RCT2_ADDRESS_PARK_NAME_ARGS);
|
||||
|
||||
platform_get_user_directory(gScenarioSavePath, "save");
|
||||
strncat(gScenarioSavePath, parkName, sizeof(gScenarioSavePath));
|
||||
strncat(gScenarioSavePath, ".sv6", sizeof(gScenarioSavePath));
|
||||
strncat(gScenarioSavePath, parkName, sizeof(gScenarioSavePath) - strlen(gScenarioSavePath) - 1);
|
||||
strncat(gScenarioSavePath, ".sv6", sizeof(gScenarioSavePath) - strlen(gScenarioSavePath) - 1);
|
||||
|
||||
strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2, (char*)RCT2_ADDRESS_SAVED_GAMES_PATH);
|
||||
strcpy((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2 + strlen((char*)RCT2_ADDRESS_SAVED_GAMES_PATH_2), gScenarioSavePath);
|
||||
|
||||
Reference in New Issue
Block a user