[Ttssh2-commit] [8478] localtime_s(), sscanf_s(), strcpy_s(), ctime_s() を使用

scmno****@osdn***** scmno****@osdn*****
2020年 1月 16日 (木) 23:20:53 JST


Revision: 8478
          https://osdn.net/projects/ttssh2/scm/svn/commits/8478
Author:   zmatsuo
Date:     2020-01-16 23:20:53 +0900 (Thu, 16 Jan 2020)
Log Message:
-----------
localtime_s(), sscanf_s(), strcpy_s(), ctime_s() を使用

Modified Paths:
--------------
    trunk/teraterm/common/ttlib.c
    trunk/teraterm/teraterm/vtwin.cpp
    trunk/teraterm/ttpdlg/ttdlg.c
    trunk/teraterm/ttpfile/kermit.c
    trunk/teraterm/ttpfile/quickvan.c
    trunk/teraterm/ttpfile/ymodem.c
    trunk/teraterm/ttpfile/zmodem.c

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.c
===================================================================
--- trunk/teraterm/common/ttlib.c	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/common/ttlib.c	2020-01-16 14:20:53 UTC (rev 8478)
@@ -717,7 +717,7 @@
 	char buf[MAX_PATH];
 	char *c;
 	time_t time_local;
-	struct tm *tm_local;
+	struct tm tm_local;
 
 	// \x83t\x83@\x83C\x83\x8B\x96\xBC\x95\x94\x95\xAA\x82݂̂\xF0 flename \x82Ɋi\x94[
 	ExtractFileName(FName, filename ,sizeof(filename));
@@ -727,10 +727,10 @@
 
 	// \x8C\xBB\x8Dݎ\x9E\x8D\x8F\x82\xF0\x8E擾
 	time(&time_local);
-	tm_local = localtime(&time_local);
+	localtime_s(&tm_local, &time_local);
 
 	// \x8E\x9E\x8D\x8F\x95\xB6\x8E\x9A\x97\xF1\x82ɕϊ\xB7
-	if (strftime(buf, sizeof(buf), filename, tm_local) == 0) {
+	if (strftime(buf, sizeof(buf), filename, &tm_local) == 0) {
 		strncpy_s(buf, sizeof(buf), filename, _TRUNCATE);
 	}
 
@@ -876,7 +876,7 @@
 	char T[15];
 
 	GetNthString(Source,Nth,sizeof(T),T);
-	if (sscanf(T, "%d", Num) != 1) {
+	if (sscanf_s(T, "%d", Num) != 1) {
 		*Num = 0;
 	}
 }
@@ -887,7 +887,7 @@
 	int v;
 
 	GetNthString(Source, Nth, sizeof(T), T);
-	if (sscanf(T, "%d", &v) != 1) {
+	if (sscanf_s(T, "%d", &v) != 1) {
 		v = defval;
 	}
 	

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/teraterm/vtwin.cpp	2020-01-16 14:20:53 UTC (rev 8478)
@@ -3920,7 +3920,7 @@
 
 	for (c = 'C' ; c <= 'Z' ; c++) {
 		char tmp[MAX_PATH];
-		sprintf(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c);
+		sprintf_s(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c);
 		if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
 			goto found_dll;
 		}
@@ -4389,7 +4389,7 @@
 					char uimsg[MAX_UIMSG];
 					get_lang_msg("FILEDLG_TRANS_TITLE_SENDFILE", uimsg, sizeof(uimsg), TitSendFile,
 								 data->UILanguageFile);
-					strcpy(title, "Tera Term: ");
+					strcpy_s(title, "Tera Term: ");
 					strncat_s(title, _countof(title), uimsg, _TRUNCATE);
 
 					size_t filter_len;

Modified: trunk/teraterm/ttpdlg/ttdlg.c
===================================================================
--- trunk/teraterm/ttpdlg/ttdlg.c	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/ttpdlg/ttdlg.c	2020-01-16 14:20:53 UTC (rev 8478)
@@ -2412,7 +2412,7 @@
 	char tmpbuf[128];
 	int msc_ver, vs_ver, msc_low_ver;
 
-	strcpy(buf, "Microsoft Visual C++");
+	strcpy_s(buf, buf_size, "Microsoft Visual C++");
 #ifdef _MSC_FULL_VER
 	// _MSC_VER  VS Ver.  VS internal Ver.  MSVC++ Ver.
 	// 1400      2005     8.0               8.0

Modified: trunk/teraterm/ttpfile/kermit.c
===================================================================
--- trunk/teraterm/ttpfile/kermit.c	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/ttpfile/kermit.c	2020-01-16 14:20:53 UTC (rev 8478)
@@ -210,7 +210,7 @@
 
 	if (fv->LogFlag) {
 		va_start(arg, fmt);
-		len = _vsnprintf(tmp, sizeof(tmp), fmt, arg);
+		len = _vsnprintf_s(tmp, sizeof(tmp), _TRUNCATE, fmt, arg);
 		va_end(arg);
 		_lwrite(fv->LogFile, tmp, len);
 		_lwrite(fv->LogFile,"\015\012",2);
@@ -716,9 +716,9 @@
 			memset(&tm, 0, sizeof(tm));
 			switch (strlen(str)) {
 				case 17:
-					if ( sscanf(str, "%04d%02d%02d %02d:%02d:%02d",
-					            &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
-					            &tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6 ) {
+					if ( sscanf_s(str, "%04d%02d%02d %02d:%02d:%02d",
+								  &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+								  &tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6 ) {
 						kv->FileTime = time(NULL);
 					} else {
 						tm.tm_year -= 1900;		// 1900-
@@ -727,9 +727,9 @@
 					}
 					break;
 				case 14:
-					if ( sscanf(str, "%04d%02d%02d %02d:%02d",
-					            &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
-					            &tm.tm_hour, &tm.tm_min) < 5 ) {
+					if ( sscanf_s(str, "%04d%02d%02d %02d:%02d",
+								  &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+								  &tm.tm_hour, &tm.tm_min) < 5 ) {
 						kv->FileTime = time(NULL);
 					} else {
 						tm.tm_year -= 1900;		// 1900-
@@ -739,8 +739,8 @@
 					}
 					break;
 				case 8:
-					if ( sscanf(str, "%04d%02d%02d",
-					            &tm.tm_year, &tm.tm_mon, &tm.tm_mday) < 3 ) {
+					if ( sscanf_s(str, "%04d%02d%02d",
+								  &tm.tm_year, &tm.tm_mon, &tm.tm_mday) < 3 ) {
 						kv->FileTime = time(NULL);
 					} else {
 						tm.tm_year -= 1900;		// 1900-
@@ -752,9 +752,9 @@
 					}
 					break;
 				case 15:
-					if ( sscanf(str, "%02d%02d%02d %02d:%02d:%02d",
-					            &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
-					            &tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6 ) {
+					if ( sscanf_s(str, "%02d%02d%02d %02d:%02d:%02d",
+								  &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+								  &tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6 ) {
 						kv->FileTime = time(NULL);
 					} else {
 						if (tm.tm_year <= 49) {
@@ -765,9 +765,9 @@
 					}
 					break;
 				case 12:
-					if ( sscanf(str, "%02d%02d%02d %02d:%02d",
-					            &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
-					            &tm.tm_hour, &tm.tm_min) < 5 ) {
+					if ( sscanf_s(str, "%02d%02d%02d %02d:%02d",
+								  &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+								  &tm.tm_hour, &tm.tm_min) < 5 ) {
 						kv->FileTime = time(NULL);
 					} else {
 						if (tm.tm_year <= 49) {
@@ -779,8 +779,8 @@
 					}
 					break;
 				case 6:
-					if ( sscanf(str, "%02d%02d%02d",
-					            &tm.tm_year, &tm.tm_mon, &tm.tm_mday) < 3 ) {
+					if ( sscanf_s(str, "%02d%02d%02d",
+								  &tm.tm_year, &tm.tm_mon, &tm.tm_mday) < 3 ) {
 						kv->FileTime = time(NULL);
 					} else {
 						if (tm.tm_year <= 49) {
@@ -799,7 +799,7 @@
 			break;
 		case ',':	// File attribute "664"
 			kv->FileAttrFlag |= KMT_ATTR_MODE;
-			sscanf(str, "%03o", &kv->FileMode);
+			sscanf_s(str, "%03o", &kv->FileMode);
 			break;
 		case '1':	// File length in bytes
 			kv->FileAttrFlag |= KMT_ATTR_SIZE;
@@ -1053,9 +1053,10 @@
 		strncat_s(buf, sizeof(buf), s, _TRUNCATE);
 	}
 	if ( (kv->FileAttrFlag & KMT_ATTR_TIME) != 0 ) {
-		struct tm *date = localtime(&kv->FileTime);
+		struct tm date;
 		int len;
-		len = strftime(t, sizeof(t), "%Y%m%d %H:%M:%S", date);
+		localtime_s(&date, &kv->FileTime);
+		len = strftime(t, sizeof(t), "%Y%m%d %H:%M:%S", &date);
 		_snprintf_s(s, sizeof(s), _TRUNCATE, "#%c%s", KmtChar(len), t);
 		strncat_s(buf, sizeof(buf), s, _TRUNCATE);
 	}
@@ -1190,7 +1191,9 @@
 	fv->LogFlag = ((ts->LogFlag & LOG_KMT)!=0);
 	if (fv->LogFlag) {
 		char buf[128];
+		char ctime_str[128];
 		time_t tm = time(NULL);
+		ctime_s(ctime_str, sizeof(ctime_str), &tm);
 
 		fv->LogFile = _lcreat("KERMIT.LOG",0);
 		fv->LogCount = 0;
@@ -1200,7 +1203,7 @@
 			kv->KmtMode == IdKmtSend ? "Send" : 
 			kv->KmtMode == IdKmtReceive ? "Receive" :
 			kv->KmtMode == IdKmtGet ? "Get" : "Finish",
-			ctime(&tm) 
+			ctime_str 
 			);
 		_lwrite(fv->LogFile, buf, strlen(buf));
 	}

Modified: trunk/teraterm/ttpfile/quickvan.c
===================================================================
--- trunk/teraterm/ttpfile/quickvan.c	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/ttpfile/quickvan.c	2020-01-16 14:20:53 UTC (rev 8478)
@@ -783,7 +783,8 @@
 {
   int i, j;
   struct stat stbuf; 
-  struct tm * tmbuf;
+  struct tm tmbuf;
+  char fullname_upper[MAX_PATH];
 
   if (! GetNextFname(fv))
   {
@@ -820,7 +821,9 @@
   QVPutNum2(qv,qv->FileNum,&i);
   /* file name */
   SetDlgItemText(fv->HWin, IDC_PROTOFNAME, &(fv->FullName[fv->DirLen]));
-  strncpy_s(&(qv->PktOut[i]),sizeof(qv->PktOut)-i,_strupr(&(fv->FullName[fv->DirLen])),_TRUNCATE);
+  strncpy_s(fullname_upper, sizeof(fullname_upper), &(fv->FullName[fv->DirLen]), _TRUNCATE);
+  _strupr_s(fullname_upper, sizeof(fullname_upper));
+  strncpy_s(&(qv->PktOut[i]),sizeof(qv->PktOut)-i,fullname_upper,_TRUNCATE);
   FTConvFName(&(qv->PktOut[i]));  // replace ' ' by '_' in FName
   i = strlen(&(qv->PktOut[i])) + i;
   qv->PktOut[i] = 0;
@@ -832,16 +835,16 @@
   i++;
   /* date */
   stat(fv->FullName,&stbuf);
-  tmbuf = localtime(&stbuf.st_mtime);
+  localtime_s(&tmbuf, &stbuf.st_mtime);
 
-  QVPutNum2(qv,(WORD)((tmbuf->tm_year+1900) / 100),&i);
-  QVPutNum2(qv,(WORD)((tmbuf->tm_year+1900) % 100),&i);
-  QVPutNum2(qv,(WORD)(tmbuf->tm_mon+1),&i);
-  QVPutNum2(qv,(WORD)tmbuf->tm_mday,&i);
+  QVPutNum2(qv,(WORD)((tmbuf.tm_year+1900) / 100),&i);
+  QVPutNum2(qv,(WORD)((tmbuf.tm_year+1900) % 100),&i);
+  QVPutNum2(qv,(WORD)(tmbuf.tm_mon+1),&i);
+  QVPutNum2(qv,(WORD)tmbuf.tm_mday,&i);
   /* time */
-  QVPutNum2(qv,(WORD)tmbuf->tm_hour,&i);
-  QVPutNum2(qv,(WORD)tmbuf->tm_min,&i);
-  QVPutNum2(qv,(WORD)tmbuf->tm_sec,&i);
+  QVPutNum2(qv,(WORD)tmbuf.tm_hour,&i);
+  QVPutNum2(qv,(WORD)tmbuf.tm_min,&i);
+  QVPutNum2(qv,(WORD)tmbuf.tm_sec,&i);
   for (j = i ; j <= 130 ; j++)
     qv->PktOut[j] = 0;
 

Modified: trunk/teraterm/ttpfile/ymodem.c
===================================================================
--- trunk/teraterm/ttpfile/ymodem.c	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/ttpfile/ymodem.c	2020-01-16 14:20:53 UTC (rev 8478)
@@ -336,11 +336,13 @@
 
 	if (fv->LogFlag) {
 		char buf[128];
+		char ctime_str[128];
 		time_t tm = time(NULL);
+		ctime_s(ctime_str, sizeof(ctime_str), &tm);
 
 		_snprintf_s(buf, sizeof(buf), _TRUNCATE, "YMODEM %s start: %s\n", 
 		            yv->YMode == IdYSend ? "Send" : "Recv",
-		            ctime(&tm));
+		            ctime_str);
 		_lwrite(fv->LogFile, buf, strlen(buf));
 	}
 
@@ -583,7 +585,7 @@
 		}
 		nameend = name + 1 + strlen(name);
 		if (*nameend) {
-			ret = sscanf(nameend, "%ld%lo%o", &bytes_total, &modtime, &mode);
+			ret = sscanf_s(nameend, "%ld%lo%o", &bytes_total, &modtime, &mode);
 			if (ret >= 1) {
 				fv->FileSize = bytes_total;
 				yv->RecvFilesize = TRUE;

Modified: trunk/teraterm/ttpfile/zmodem.c
===================================================================
--- trunk/teraterm/ttpfile/zmodem.c	2020-01-16 14:20:42 UTC (rev 8477)
+++ trunk/teraterm/ttpfile/zmodem.c	2020-01-16 14:20:53 UTC (rev 8478)
@@ -1040,7 +1040,7 @@
 	/* file mtime */
 	p = zv->PktIn + i;
 	if (*p) {
-		ret = sscanf(p, "%lo%o", &modtime, &mode);
+		ret = sscanf_s(p, "%lo%o", &modtime, &mode);
 		if (ret >= 1) {
 			fv->FileMtime = modtime;
 		}


Ttssh2-commit メーリングリストの案内