[Ttssh2-commit] [7930] 不要なHANDLEキャストを削除

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 8月 9日 (金) 22:36:46 JST


Revision: 7930
          https://osdn.net/projects/ttssh2/scm/svn/commits/7930
Author:   zmatsuo
Date:     2019-08-09 22:36:46 +0900 (Fri, 09 Aug 2019)
Log Message:
-----------
不要なHANDLEキャストを削除

- コンパイラの型チェックを積極的に利用するのが目的
- 出力されるコードは特に変化ない

Modified Paths:
--------------
    trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c
    trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.h
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/teraterm/telnet.c
    trunk/teraterm/teraterm/ttdde.c
    trunk/teraterm/ttpmacro/wait4all.c
    trunk/ttssh2/ttxssh/ssh.c

-------------- next part --------------
Modified: trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c
===================================================================
--- trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.c	2019-08-09 13:36:46 UTC (rev 7930)
@@ -34,9 +34,26 @@
 #include <wspiapi.h>
 #include <windows.h>
 #include <process.h>
+#include <crtdbg.h>
 #include "WSAAsyncGetAddrInfo.h"
 #include "ttwsk.h"
 
+struct getaddrinfo_args {
+  HWND hWnd;
+  unsigned int wMsg;
+  char *hostname;
+  char *portname;
+  struct addrinfo hints;
+  struct addrinfo **res;
+  HANDLE *lpHandle;
+};
+
+#ifdef _DEBUG
+#define malloc(l)	_malloc_dbg((l), _NORMAL_BLOCK, __FILE__, __LINE__)
+#define free(p)		_free_dbg((p), _NORMAL_BLOCK)
+#define _strdup(s)	_strdup_dbg((s), _NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
 static unsigned __stdcall getaddrinfo_thread(void * p);
 
 HANDLE PASCAL WSAAsyncGetAddrInfo(HWND hWnd, unsigned int wMsg,
@@ -73,7 +90,7 @@
 
 	/* create sub-thread running getaddrinfo() */
 	thread = (HANDLE)_beginthreadex(NULL, 0, getaddrinfo_thread, ga, CREATE_SUSPENDED, &tid);
-	*ga->lpHandle = (HANDLE)thread;
+	*ga->lpHandle = thread;
 	ResumeThread(thread);
 
 	/* return thread handle */
@@ -84,7 +101,7 @@
 		free(ga);
 		return NULL;
 	} else
-		return (HANDLE)thread;
+		return thread;
 }
 
 static unsigned __stdcall getaddrinfo_thread(void * p)

Modified: trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.h
===================================================================
--- trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.h	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/teraterm/teraterm/WSAAsyncGetAddrInfo.h	2019-08-09 13:36:46 UTC (rev 7930)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2017 TeraTerm Project
+ * Copyright (C) 2010-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -36,16 +36,6 @@
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
-struct getaddrinfo_args {
-  HWND hWnd;
-  unsigned int wMsg;
-  char *hostname;
-  char *portname;
-  struct addrinfo hints;
-  struct addrinfo **res;
-  HANDLE *lpHandle;
-};
-
 HANDLE PASCAL WSAAsyncGetAddrInfo(HWND hWnd,
 			   unsigned int wMsg,
 			   const char *hostname,

Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/teraterm/teraterm/filesys.cpp	2019-08-09 13:36:46 UTC (rev 7930)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2005-2018 TeraTerm Project
+ * (C) 2005-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -428,7 +428,7 @@
 	if (!ptr->FileOpen)
 		return;
 
-	if (ptr->LogThread != (HANDLE)-1) {
+	if (ptr->LogThread != INVALID_HANDLE_VALUE) {
 		// \x83X\x83\x8C\x83b\x83h\x82̏I\x97\xB9\x91҂\xBF
 		ret = PostThreadMessage(ptr->LogThreadId, WM_QUIT, 0, 0);
 		if (ret != 0) {
@@ -439,9 +439,9 @@
 			code = GetLastError();
 		}
 		CloseHandle(ptr->LogThread);
-		ptr->LogThread = (HANDLE)-1;
+		ptr->LogThread = INVALID_HANDLE_VALUE;
 	}
-	CloseHandle((HANDLE)ptr->FileHandle);
+	CloseHandle(ptr->FileHandle);
 }
 
 // \x92x\x89\x84\x8F\x91\x82\xAB\x8D\x9E\x82ݗp\x83X\x83\x8C\x83b\x83h
@@ -465,7 +465,7 @@
 			case WM_DPC_LOGTHREAD_SEND:
 				buf = (PCHAR)msg.wParam;
 				buflen = (DWORD)msg.lParam;
-				WriteFile((HANDLE)LogVar->FileHandle, buf, buflen, &wrote, NULL);
+				WriteFile(LogVar->FileHandle, buf, buflen, &wrote, NULL);
 				free(buf);   // \x82\xB1\x82\xB1\x82Ń\x81\x83\x82\x83\x8A\x89\xF0\x95\xFA
 				break;
 
@@ -689,7 +689,7 @@
 	// \x8Dŏ\x89\x82̃t\x83@\x83C\x83\x8B\x82\xAA\x90ݒ肵\x82\xBD\x83T\x83C\x83Y\x82Ń\x8D\x81[\x83e\x81[\x83g\x82\xB5\x82Ȃ\xA2\x96\xE2\x91\xE8\x82̏C\x90\xB3\x81B
 	// (2016.4.9 yutaka)
 	if (LogVar->RotateMode != ROTATE_NONE) {
-		size = GetFileSize((HANDLE)LogVar->FileHandle, NULL);
+		size = GetFileSize(LogVar->FileHandle, NULL);
 		if (size != -1)
 			LogVar->ByteCount = size;
 	}
@@ -736,8 +736,8 @@
 				PostThreadMessage(LogVar->LogThreadId, WM_DPC_LOGTHREAD_SEND, (WPARAM)pbuf, size + 2);
 			} else { // \x92\xBC\x8F\x91\x82\xAB\x81B\x83l\x83b\x83g\x83\x8F\x81[\x83N\x8Co\x97R\x82\xBE\x82ƒx\x82\xA2\x81B
 #endif
-				WriteFile((HANDLE)LogVar->FileHandle, buf, size, &written_size, NULL);
-				WriteFile((HANDLE)LogVar->FileHandle, crlf, crlf_len, &written_size, NULL);
+				WriteFile(LogVar->FileHandle, buf, size, &written_size, NULL);
+				WriteFile(LogVar->FileHandle, crlf, crlf_len, &written_size, NULL);
 #if 0
 			}
 #endif
@@ -846,8 +846,8 @@
 	}
 
 	logfile_lock();
-	WriteFile((HANDLE)LogVar->FileHandle, buf, size, &wrote, NULL);
-	WriteFile((HANDLE)LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // \x89\xFC\x8Ds
+	WriteFile(LogVar->FileHandle, buf, size, &wrote, NULL);
+	WriteFile(LogVar->FileHandle, "\r\n", 2, &wrote, NULL); // \x89\xFC\x8Ds
 	/* Set Line End Flag
 		2007.05.24 Gentaro
 	*/
@@ -1054,9 +1054,9 @@
 						strtime = strelapsed(cv.ConnectedTime);
 						break;
 					}
-					WriteFile((HANDLE)LogVar->FileHandle, "[", 1, &wrote, NULL);
-					WriteFile((HANDLE)LogVar->FileHandle, strtime, strlen(strtime), &wrote, NULL);
-					WriteFile((HANDLE)LogVar->FileHandle, "] ", 2, &wrote, NULL);
+					WriteFile(LogVar->FileHandle, "[", 1, &wrote, NULL);
+					WriteFile(LogVar->FileHandle, strtime, strlen(strtime), &wrote, NULL);
+					WriteFile(LogVar->FileHandle, "] ", 2, &wrote, NULL);
 				}
 
 				/* 2007.05.24 Gentaro */
@@ -1067,7 +1067,7 @@
 					eLineEnd = Line_Other; /* clear endmark*/
 				}
 
-				WriteFile((HANDLE)LogVar->FileHandle, (PCHAR)&b, 1, &wrote, NULL);
+				WriteFile(LogVar->FileHandle, (PCHAR)&b, 1, &wrote, NULL);
 				(LogVar->ByteCount)++;
 			}
 		}
@@ -1305,7 +1305,7 @@
 
 	do {
 		if (FileSendHandler.pos == FileSendHandler.end) {
-			ReadFile((HANDLE)SendVar->FileHandle, &(FileSendHandler.buf[0]), sizeof(FileSendHandler.buf), &read_bytes, NULL);
+			ReadFile(SendVar->FileHandle, &(FileSendHandler.buf[0]), sizeof(FileSendHandler.buf), &read_bytes, NULL);
 			fc = LOWORD(read_bytes);
 			FileSendHandler.pos = 0;
 			FileSendHandler.end = fc;
@@ -1384,12 +1384,12 @@
 			}
 		}
 		else if (! FileReadEOF) {
-			ReadFile((HANDLE)SendVar->FileHandle, &FileByte, 1, &read_bytes, NULL);
+			ReadFile(SendVar->FileHandle, &FileByte, 1, &read_bytes, NULL);
 			fc = LOWORD(read_bytes);
 			SendVar->ByteCount = SendVar->ByteCount + fc;
 
 			if (FileCRSend && (fc==1) && (FileByte==0x0A)) {
-				ReadFile((HANDLE)SendVar->FileHandle, &FileByte, 1, &read_bytes, NULL);
+				ReadFile(SendVar->FileHandle, &FileByte, 1, &read_bytes, NULL);
 				fc = LOWORD(read_bytes);
 				SendVar->ByteCount = SendVar->ByteCount + fc;
 			}

Modified: trunk/teraterm/teraterm/telnet.c
===================================================================
--- trunk/teraterm/teraterm/telnet.c	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/teraterm/teraterm/telnet.c	2019-08-09 13:36:46 UTC (rev 7930)
@@ -69,7 +69,7 @@
 
 static TelRec tr;
 
-static HANDLE keepalive_thread = (HANDLE)-1L;
+static HANDLE keepalive_thread = INVALID_HANDLE_VALUE;
 static HWND keepalive_dialog = NULL;
 int nop_interval = 0;
 
@@ -796,7 +796,7 @@
 
 #define WM_SEND_HEARTBEAT (WM_USER + 1)
 
-static LRESULT CALLBACK telnet_heartbeat_dlg_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
+static INT_PTR CALLBACK telnet_heartbeat_dlg_proc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
 {
 	switch (msg) {
 	case WM_INITDIALOG:
@@ -857,9 +857,9 @@
 	if (ts.TelKeepAliveInterval > 0) {
 		nop_interval = ts.TelKeepAliveInterval;
 
-	// \x83\x82\x81[\x83h\x83\x8C\x83X\x83_\x83C\x83A\x83\x8D\x83O\x82\xF0\x92lj\xC1 (2007.12.26 yutaka)
-	keepalive_dialog = CreateDialog(hInst, MAKEINTRESOURCE(IDD_BROADCAST_DIALOG),
-	                                HVTWin, (DLGPROC)telnet_heartbeat_dlg_proc);
+		// \x83\x82\x81[\x83h\x83\x8C\x83X\x83_\x83C\x83A\x83\x8D\x83O\x82\xF0\x92lj\xC1 (2007.12.26 yutaka)
+		keepalive_dialog = CreateDialog(hInst, MAKEINTRESOURCE(IDD_BROADCAST_DIALOG),
+										HVTWin, telnet_heartbeat_dlg_proc);
 
 		keepalive_thread = (HANDLE)_beginthreadex(NULL, 0, TelKeepAliveThread, NULL, 0, &tid);
 		if (keepalive_thread == (HANDLE)-1) {
@@ -869,11 +869,11 @@
 }
 
 void TelStopKeepAliveThread() {
-	if (keepalive_thread != (HANDLE)-1L) {
+	if (keepalive_thread != INVALID_HANDLE_VALUE) {
 		nop_interval = 0;
 		WaitForSingleObject(keepalive_thread, INFINITE);
 		CloseHandle(keepalive_thread);
-		keepalive_thread = (HANDLE)-1L;
+		keepalive_thread = INVALID_HANDLE_VALUE;
 
 		DestroyWindow(keepalive_dialog);
 	}
@@ -881,9 +881,9 @@
 
 void TelUpdateKeepAliveInterval() {
 	if (cv.Open && cv.TelFlag && ts.TCPPort==ts.TelPort) {
-		if (ts.TelKeepAliveInterval > 0 && keepalive_thread == (HANDLE)-1)
+		if (ts.TelKeepAliveInterval > 0 && keepalive_thread == INVALID_HANDLE_VALUE)
 			TelStartKeepAliveThread();
-		else if (ts.TelKeepAliveInterval == 0 && keepalive_thread != (HANDLE)-1)
+		else if (ts.TelKeepAliveInterval == 0 && keepalive_thread != INVALID_HANDLE_VALUE)
 			TelStopKeepAliveThread();
 		else
 			nop_interval = ts.TelKeepAliveInterval;

Modified: trunk/teraterm/teraterm/ttdde.c
===================================================================
--- trunk/teraterm/teraterm/ttdde.c	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/teraterm/teraterm/ttdde.c	2019-08-09 13:36:46 UTC (rev 7930)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2004-2017 TeraTerm Project
+ * (C) 2004-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -565,7 +565,7 @@
 		if (LogVar != NULL)
 		{
 			DWORD wrote;
-			WriteFile((HANDLE)LogVar->FileHandle, ParamFileName, strlen(ParamFileName), &wrote, NULL);
+			WriteFile(LogVar->FileHandle, ParamFileName, strlen(ParamFileName), &wrote, NULL);
 			LogVar->ByteCount =
 				LogVar->ByteCount + strlen(ParamFileName);
 			FLogRefreshNum();

Modified: trunk/teraterm/ttpmacro/wait4all.c
===================================================================
--- trunk/teraterm/ttpmacro/wait4all.c	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/teraterm/ttpmacro/wait4all.c	2019-08-09 13:36:46 UTC (rev 7930)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2017 TeraTerm Project
+ * Copyright (C) 2009-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -79,7 +79,7 @@
 static int open_macro_shmem(void)
 {
 	HMap = CreateFileMapping(
-		(HANDLE) 0xFFFFFFFF, NULL, PAGE_READWRITE,
+		INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
 		0, sizeof(TMacroShmem), TTM_FILEMAPNAME);
 	if (HMap == NULL)
 		return FALSE;

Modified: trunk/ttssh2/ttxssh/ssh.c
===================================================================
--- trunk/ttssh2/ttxssh/ssh.c	2019-08-09 03:23:44 UTC (rev 7929)
+++ trunk/ttssh2/ttxssh/ssh.c	2019-08-09 13:36:46 UTC (rev 7930)
@@ -218,7 +218,7 @@
 	if (type == TYPE_SCP) {
 		c->scp.state = SCP_INIT;
 		c->scp.progress_window = NULL;
-		c->scp.thread = (HANDLE)-1;
+		c->scp.thread = INVALID_HANDLE_VALUE;
 		c->scp.localfp = NULL;
 		c->scp.filemtime = 0;
 		c->scp.fileatime = 0;
@@ -345,10 +345,10 @@
 			DestroyWindow(c->scp.progress_window);
 			c->scp.progress_window = NULL;
 		}
-		if (c->scp.thread != (HANDLE)-1L) {
+		if (c->scp.thread != INVALID_HANDLE_VALUE) {
 			WaitForSingleObject(c->scp.thread, INFINITE);
 			CloseHandle(c->scp.thread);
-			c->scp.thread = (HANDLE)-1L;
+			c->scp.thread = INVALID_HANDLE_VALUE;
 		}
 
 		ssh2_scp_free_packetlist(c);
@@ -6813,7 +6813,7 @@
 
 static void start_ssh_heartbeat_thread(PTInstVar pvar)
 {
-	HANDLE thread = (HANDLE)-1;
+	HANDLE thread = INVALID_HANDLE_VALUE;
 	unsigned tid;
 	HWND hDlgWnd;
 
@@ -6834,10 +6834,10 @@
 // \x83X\x83\x8C\x83b\x83h\x82̒\xE2\x8E~ (2004.12.27 yutaka)
 void halt_ssh_heartbeat_thread(PTInstVar pvar)
 {
-	if (pvar->ssh_heartbeat_thread != (HANDLE)-1L) {
+	if (pvar->ssh_heartbeat_thread != INVALID_HANDLE_VALUE) {
 		WaitForSingleObject(pvar->ssh_heartbeat_thread, INFINITE);
 		CloseHandle(pvar->ssh_heartbeat_thread);
-		pvar->ssh_heartbeat_thread = (HANDLE)-1L;
+		pvar->ssh_heartbeat_thread = INVALID_HANDLE_VALUE;
 
 		DestroyWindow(pvar->ssh_hearbeat_dialog);
 	}


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