[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40926] trunk/blender/source/blender/ blenlib/intern/path_util.c: fix for crash in BLI_join_dirfile() when the dir is longer then the target string.

Campbell Barton ideasman42 at gmail.com
Tue Oct 11 07:21:24 CEST 2011


Revision: 40926
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40926
Author:   campbellbarton
Date:     2011-10-11 05:21:24 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
fix for crash in BLI_join_dirfile() when the dir is longer then the target string.

starting blender in a dir longer then 240 chars would crash.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/path_util.c

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c	2011-10-11 05:18:33 UTC (rev 40925)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c	2011-10-11 05:21:24 UTC (rev 40926)
@@ -1433,16 +1433,16 @@
 void BLI_join_dirfile(char *string, const size_t maxlen, const char *dir, const char *file)
 {
 	int sl_dir;
-	
+
 	if(string != dir) /* compare pointers */
-		BLI_strncpy(string, dir, maxlen);
+		BLI_strncpy(string, dir, maxlen -(file ? 1 : 0));
 
 	if (!file)
 		return;
-	
+
 	sl_dir= BLI_add_slash(string);
 	
-	if (sl_dir <FILE_MAX) {
+	if (sl_dir < maxlen) {
 		BLI_strncpy(string + sl_dir, file, maxlen - sl_dir);
 	}
 }
@@ -1584,19 +1584,11 @@
 int BLI_add_slash(char *string)
 {
 	int len = strlen(string);
-#ifdef WIN32
-	if (len==0 || string[len-1]!='\\') {
-		string[len] = '\\';
+	if (len==0 || string[len-1] != SEP) {
+		string[len] = SEP;
 		string[len+1] = '\0';
 		return len+1;
 	}
-#else
-	if (len==0 || string[len-1]!='/') {
-		string[len] = '/';
-		string[len+1] = '\0';
-		return len+1;
-	}
-#endif
 	return len;
 }
 
@@ -1605,11 +1597,7 @@
 {
 	int len = strlen(string);
 	while (len) {
-#ifdef WIN32
-		if (string[len-1]=='\\') {
-#else
-		if (string[len-1]=='/') {
-#endif
+		if (string[len-1] == SEP) {
 			string[len-1] = '\0';
 			len--;
 		} else {




More information about the Bf-blender-cvs mailing list