[Ttssh2-commit] [4388] strremoveによる文字列変数操作で

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 17日 (木) 19:12:07 JST


Revision: 4388
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4388
Author:   yutakapon
Date:     2011-03-17 19:12:07 +0900 (Thu, 17 Mar 2011)

Log Message:
-----------
strremoveによる文字列変数操作で
例として
130バイト文字列の最後尾1文字を削除させると
操作対象文字列の次に宣言された文字列の先頭が書き換えられてしまう。
http://sourceforge.jp/ticket/browse.php?group_id=1412&tid=24631

という問題に対する修正を行った。

Modified Paths:
--------------
    trunk/teraterm/ttpmacro/ttl.c


-------------- next part --------------
Modified: trunk/teraterm/ttpmacro/ttl.c
===================================================================
--- trunk/teraterm/ttpmacro/ttl.c	2011-03-15 13:09:19 UTC (rev 4387)
+++ trunk/teraterm/ttpmacro/ttl.c	2011-03-17 10:12:07 UTC (rev 4388)
@@ -3661,7 +3661,7 @@
 static void remove_string(char *str, int index, int len)
 {
 	char *np;
-	int srclen;
+	int srclen, copylen;
 
 	srclen = strlen(str);
 
@@ -3669,8 +3669,23 @@
 		return;
 	}
 
+	/*
+	   remove_string(str, 6, 4);
+
+	   <------------>srclen
+			 <-->len
+	   XXXXXX****YYY
+	        ^index(np)
+			     ^np+len 
+				 <-->srclen - len - index
+		    «
+	   XXXXXXYYY
+	 */
+
 	np = str + (index - 1);
-	memmove_s(np, MaxStrLen, np + len, srclen - len);
+	copylen = srclen - len - (index - 1);
+	if (copylen > 0)
+		memmove_s(np, MaxStrLen, np + len, copylen);
 
 	// null-terminate
 	str[srclen - len] = '\0';



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