diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 76c61c83b..2b4536436 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -132,6 +132,7 @@ endif ifeq ($(WALTJE), y) +OPENDIR = win_opendir.o SERIAL = serial.o WSERIAL = win_serial.o WFLAGS = -DWALTJE @@ -241,7 +242,7 @@ VIDOBJ = video.o \ WINOBJ = win.o \ win_ddraw.o win_ddraw_fs.o win_ddraw_screenshot.o \ win_d3d.o win_d3d_fs.o \ - win_language.o win_status.o win_opendir.o win_dynld.o \ + win_language.o win_status.o $(OPENDIR) win_dynld.o \ win_video.o $(WSERIAL) win_keyboard.o win_mouse.o \ win_iodev.o win_joystick.o win_midi.o \ win_settings.o win_deviceconfig.o win_joystickconfig.o \ diff --git a/src/WIN/win_language.c b/src/WIN/win_language.c index ed4e19159..84eabd1b7 100644 --- a/src/WIN/win_language.c +++ b/src/WIN/win_language.c @@ -198,7 +198,7 @@ int file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, int save) } if (r) { - wcstombs(openfilestring, wopenfilestring, 520); + wcstombs(openfilestring, wopenfilestring, sizeof(openfilestring)); pclog("File dialog return true\n"); return 0; } diff --git a/src/WIN/win_settings.c b/src/WIN/win_settings.c index 6bcaab48f..6000827be 100644 --- a/src/WIN/win_settings.c +++ b/src/WIN/win_settings.c @@ -663,7 +663,7 @@ static BOOL CALLBACK win_settings_machine_proc(HWND hdlg, UINT message, WPARAM w h = GetDlgItem(hdlg, IDC_MEMTEXT); SendMessage(h, WM_GETTEXT, 255, (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, (wcslen(lptsTemp) * 2) + 2); + wcstombs(stransi, lptsTemp, sizeof(stransi)); sscanf(stransi, "%i", &temp_mem_size); temp_mem_size &= ~(models[temp_model].ram_granularity - 1); if (temp_mem_size < models[temp_model].min_ram) @@ -765,7 +765,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, (wcslen(lptsTemp) * 2) + 2); + wcstombs(stransi, lptsTemp, sizeof(stransi)); gfx = video_card_getid(stransi); h = GetDlgItem(hdlg, IDC_CONFIGURE_VID); @@ -792,7 +792,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, (wcslen(lptsTemp) * 2) + 2); + wcstombs(stransi, lptsTemp, sizeof(stransi)); gfx = video_card_getid(stransi); temp_gfxcard = video_new_to_old(gfx); @@ -828,7 +828,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, (wcslen(lptsTemp) * 2) + 2); + wcstombs(stransi, lptsTemp, sizeof(stransi)); deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(stransi))); free(stransi); @@ -843,7 +843,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa h = GetDlgItem(hdlg, IDC_COMBO_VIDEO); SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp); - wcstombs(stransi, lptsTemp, (wcslen(lptsTemp) * 2) + 2); + wcstombs(stransi, lptsTemp, sizeof(stransi)); temp_gfxcard = video_new_to_old(video_card_getid(stransi)); h = GetDlgItem(hdlg, IDC_COMBO_VIDEO_SPEED); @@ -2436,7 +2436,7 @@ static void get_edit_box_contents(HWND hdlg, int id, uint64_t *val) h = GetDlgItem(hdlg, id); SendMessage(h, WM_GETTEXT, 255, (LPARAM) szText); - wcstombs(stransi, szText, (wcslen(szText) * 2) + 2); + wcstombs(stransi, szText, sizeof(stransi)); sscanf(stransi, "%" PRIu64, val); } diff --git a/src/cdrom_image.cc b/src/cdrom_image.cc index 204708742..a7fee4477 100644 --- a/src/cdrom_image.cc +++ b/src/cdrom_image.cc @@ -985,7 +985,7 @@ int image_open(uint8_t id, wchar_t *fn) } cdimg[id] = new CDROM_Interface_Image(); - wcstombs(afn, fn, (wcslen(fn) << 1) + 2); + wcstombs(afn, fn, sizeof(afn)); if (!cdimg[id]->SetDevice(afn, false)) { image_close(id); diff --git a/src/config.c b/src/config.c index e59225fed..9821b3f5a 100644 --- a/src/config.c +++ b/src/config.c @@ -225,7 +225,7 @@ int config_load(wchar_t *fn) strncpy(new_entry->name, ename, 256); memcpy(new_entry->wdata, &cfgbuffer[data_pos], 512); new_entry->wdata[255] = L'\0'; - wcstombs(new_entry->data, new_entry->wdata, 512); + wcstombs(new_entry->data, new_entry->wdata, sizeof(new_entry->data)); new_entry->data[255] = '\0'; list_add(&new_entry->list, ¤t_section->entry_head); }