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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user