1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Add safe_strncpy function

safe_strncpy is similar to strncpy, but makes sure buffer is
null-terminated. Update most of project to use this updated function to
prevent illegal memory accesses.
This commit is contained in:
Michał Janiszewski
2015-10-30 15:18:29 +01:00
parent 653c2b2701
commit 9284930d7e
41 changed files with 208 additions and 160 deletions

View File

@@ -43,6 +43,7 @@
#include "../title.h"
#include "dropdown.h"
#include "error.h"
#include "../util/util.h"
enum WINDOW_OPTIONS_PAGE {
WINDOW_OPTIONS_PAGE_DISPLAY,
@@ -1039,8 +1040,7 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown
char* devicename = gAudioDevices[dropdownIndex].name;
Mixer_Init(devicename);
SafeFree(gConfigSound.device);
gConfigSound.device = malloc(strlen(devicename) + 1);
strcpy(gConfigSound.device, devicename);
gConfigSound.device = strndup(devicename, AUDIO_DEVICE_NAME_SIZE);
}
config_save_default();
}