Revision: 34794
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34794
Author:   campbellbarton
Date:     2011-02-12 10:37:37 +0000 (Sat, 12 Feb 2011)
Log Message:
-----------
fix for uninitialized value in BLI_path_cwd() if PWD wasn't defined and the CWD 
was longer then 160.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_storage.h
    trunk/blender/source/blender/blenlib/BLI_string.h
    trunk/blender/source/blender/blenlib/intern/path_util.c
    trunk/blender/source/blender/blenlib/intern/storage.c
    trunk/blender/source/blender/blenlib/intern/string.c
    trunk/blender/source/blender/editors/interface/interface_icons.c
    trunk/blender/source/blender/editors/space_file/filelist.c

Modified: trunk/blender/source/blender/blenlib/BLI_storage.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_storage.h  2011-02-12 10:18:21 UTC 
(rev 34793)
+++ trunk/blender/source/blender/blenlib/BLI_storage.h  2011-02-12 10:37:37 UTC 
(rev 34794)
@@ -44,7 +44,7 @@
 size_t BLI_filesize(int file);
 size_t BLI_filepathsize(const char *path);
 double BLI_diskfree(const char *dir);
-char *BLI_getwdN(const char *dir);
+char *BLI_getwdN(char *dir, const int maxncpy);
 
 unsigned int BLI_getdir(const char *dirname, struct direntry **filelist);
 /**

Modified: trunk/blender/source/blender/blenlib/BLI_string.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_string.h   2011-02-12 10:18:21 UTC 
(rev 34793)
+++ trunk/blender/source/blender/blenlib/BLI_string.h   2011-02-12 10:37:37 UTC 
(rev 34794)
@@ -74,7 +74,7 @@
         *   the size of dst)
         * @retval Returns dst
         */
-char *BLI_strncpy(char *dst, const char *src, int maxncpy);
+char *BLI_strncpy(char *dst, const char *src, const int maxncpy);
 
        /* Makes a copy of the text within the "" that appear after some text 
'blahblah'
         * i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab 
"apples"

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c     2011-02-12 
10:18:21 UTC (rev 34793)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c     2011-02-12 
10:37:37 UTC (rev 34794)
@@ -753,7 +753,7 @@
        
        if (wasrelative==1) {
                char cwd[FILE_MAXDIR + FILE_MAXFILE];
-               BLI_getwdN(cwd); /* incase the full path to the blend isnt used 
*/
+               BLI_getwdN(cwd, sizeof(cwd)); /* incase the full path to the 
blend isnt used */
                
                if (cwd[0] == '\0') {
                        printf( "Could not get the current working directory - 
$PWD for an unknown reason.");
@@ -979,7 +979,7 @@
        }
 
        /* try CWD/release/folder_name */
-       if(test_path(targetpath, BLI_getwdN(cwd), "release", relfolder))
+       if(test_path(targetpath, BLI_getwdN(cwd, sizeof(cwd)), "release", 
relfolder))
                return 1;
        
        /* try EXECUTABLE_DIR/release/folder_name */
@@ -1645,6 +1645,7 @@
        return (retval);
 }
 
+/* filename must be FILE_MAX length minimum */
 void BLI_where_am_i(char *fullname, const char *name)
 {
        char filename[FILE_MAXDIR+FILE_MAXFILE];
@@ -1681,7 +1682,7 @@
                strcpy(fullname, name);
                if (name[0] == '.') {
                        // relative path, prepend cwd
-                       BLI_getwdN(fullname);
+                       BLI_getwdN(fullname, FILE_MAX);
                        
                        // not needed but avoids annoying /./ in name
                        if(name && name[0]=='.' && name[1]==slash)

Modified: trunk/blender/source/blender/blenlib/intern/storage.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/storage.c       2011-02-12 
10:18:21 UTC (rev 34793)
+++ trunk/blender/source/blender/blenlib/intern/storage.c       2011-02-12 
10:37:37 UTC (rev 34794)
@@ -103,18 +103,16 @@
 static struct ListBase *dirbase = &dirbase_;
 
 
-char *BLI_getwdN(char *dir)
+char *BLI_getwdN(char *dir, const int maxncpy)
 {
-       char *pwd;
-
        if (dir) {
-               pwd = getenv("PWD");
+               const char *pwd= getenv("PWD");
                if (pwd){
-                       strcpy(dir, pwd);
+                       BLI_strncpy(dir, pwd, maxncpy);
                        return(dir);
                }
-               /* 160 is FILE_MAXDIR in filesel.c */
-               return( getcwd(dir, 160) );
+
+               return getcwd(dir, maxncpy);
        }
        return(0);
 }

Modified: trunk/blender/source/blender/blenlib/intern/string.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/string.c        2011-02-12 
10:18:21 UTC (rev 34793)
+++ trunk/blender/source/blender/blenlib/intern/string.c        2011-02-12 
10:37:37 UTC (rev 34794)
@@ -66,7 +66,7 @@
        return n;
 }
 
-char *BLI_strncpy(char *dst, const char *src, int maxncpy) {
+char *BLI_strncpy(char *dst, const char *src, const int maxncpy) {
        int srclen= strlen(src);
        int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen;
        

Modified: trunk/blender/source/blender/editors/interface/interface_icons.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_icons.c    
2011-02-12 10:18:21 UTC (rev 34793)
+++ trunk/blender/source/blender/editors/interface/interface_icons.c    
2011-02-12 10:37:37 UTC (rev 34794)
@@ -614,7 +614,7 @@
        
        /* since BLI_getdir changes the current working directory, restore it 
           back to old value afterwards */
-       if(!BLI_getwdN(olddir)) 
+       if(!BLI_getwdN(olddir, sizeof(olddir))) 
                restoredir = 0;
        totfile = BLI_getdir(icondirstr, &dir);
        if (restoredir && !chdir(olddir)) {} /* fix warning about checking 
return value */

Modified: trunk/blender/source/blender/editors/space_file/filelist.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/filelist.c  2011-02-12 
10:18:21 UTC (rev 34793)
+++ trunk/blender/source/blender/editors/space_file/filelist.c  2011-02-12 
10:37:37 UTC (rev 34794)
@@ -839,7 +839,7 @@
        filelist->fidx = 0;
        filelist->filelist = 0;
 
-       BLI_getwdN(wdir);        
+       BLI_getwdN(wdir, sizeof(wdir));  
 
        BLI_cleanup_dir(G.main->name, filelist->dir);
        filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist));

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to