[Ttssh2-commit] [9196] ログインダイアログがうまく表示されないことがあったので修正

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2021年 3月 13日 (土) 23:42:32 JST


Revision: 9196
          https://osdn.net/projects/ttssh2/scm/svn/commits/9196
Author:   zmatsuo
Date:     2021-03-13 23:42:32 +0900 (Sat, 13 Mar 2021)
Log Message:
-----------
ログインダイアログがうまく表示されないことがあったので修正

- VS2005でビルドして Windows 95 で動作した場合
- サイズの大きなローカル変数をヒープに移動

Modified Paths:
--------------
    trunk/teraterm/ttpcmn/ttcmn.c

-------------- next part --------------
Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2021-03-06 11:02:18 UTC (rev 9195)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2021-03-13 14:42:32 UTC (rev 9196)
@@ -2679,15 +2679,21 @@
 int WINAPI DetectComPorts(LPWORD ComPortTable, int ComPortMax, char **ComPortDesc)
 {
 	HMODULE h;
-	TCHAR   devicesBuff[65535];
-	TCHAR   *p;
+	char   *devicesBuff;
+	char   *p;
 	int     comports = 0;
 	int     i, j, min;
 	WORD    s;
+	size_t buf_size = 65535;
 
+	devicesBuff = malloc(buf_size);
+	if (devicesBuff == NULL) {
+		return 0;
+	}
+
 	if (((h = GetModuleHandle("kernel32.dll")) != NULL) &&
 	    (GetProcAddress(h, "QueryDosDeviceA") != NULL) &&
-	    (QueryDosDevice(NULL, devicesBuff, 65535) != 0)) {
+	    (QueryDosDevice(NULL, devicesBuff, buf_size) != 0)) {
 		p = devicesBuff;
 		while (*p != '\0') {
 			if (strncmp(p, "COM", 3) == 0 && p[3] != '\0') {
@@ -2728,6 +2734,8 @@
 #endif
 	}
 
+	free(devicesBuff);
+
 	ListupSerialPort(ComPortTable, comports, ComPortDesc, ComPortMax);
 
 	return comports;
@@ -2736,7 +2744,7 @@
 int WINAPI CheckComPort(WORD ComPort)
 {
 	HMODULE h;
-	TCHAR   devicesBuff[65535];
+	char *devicesBuff;
 	char    com_str[64];
 	BOOL bRet;
 	GUID ClassGuid[1];
@@ -2744,6 +2752,7 @@
 	HDEVINFO DeviceInfoSet = NULL;
 	SP_DEVINFO_DATA DeviceInfoData;
 	int found = 0;
+	size_t buf_size = 65535;
 
 	_snprintf_s(com_str, sizeof(com_str), _TRUNCATE, "COM%d", ComPort);
 
@@ -2752,8 +2761,14 @@
 		return -1;
 	}
 
-	if (QueryDosDevice(com_str, devicesBuff, 65535) == 0) {
+	devicesBuff = malloc(buf_size);
+	if (devicesBuff == NULL) {
+		return -1;
+	}
+
+	if (QueryDosDevice(com_str, devicesBuff, buf_size) == 0) {
 		DWORD err = GetLastError();
+		free(devicesBuff);
 		if (err == ERROR_FILE_NOT_FOUND) {
 			/* NOT FOUND */
 			return 0;
@@ -2765,11 +2780,13 @@
 	/* QueryDosDevice\x82Őؒf\x82\xF0\x8C\x9F\x92m\x82ł\xAB\x82Ȃ\xA2\x8A‹\xAB\x82\xAA\x82\xA0\x82\xE9\x82ł\xB3\x82\xE7\x82Ƀ`\x83F\x83b\x83N */
 	bRet = SetupDiClassGuidsFromName(_T("PORTS"), (LPGUID) & ClassGuid, 1, &dwRequiredSize);
 	if (bRet == FALSE) {
+		free(devicesBuff);
 		return -1;
 	}
 
 	DeviceInfoSet = SetupDiGetClassDevs(&ClassGuid[0], NULL, NULL, DIGCF_PRESENT | DIGCF_PROFILE);
 	if (DeviceInfoSet == NULL) {
+		free(devicesBuff);
 		return -1;
 	}
 
@@ -2799,6 +2816,7 @@
 
 	SetupDiDestroyDeviceInfoList(DeviceInfoSet);
 
+	free(devicesBuff);
 	return found;
 }
 


Ttssh2-commit メーリングリストの案内
Back to archive index