Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-12 13:37:37 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-12 13:37:37 +0300
commit6e47ffcc0d076596429b49cb283757b1952f7b86 (patch)
tree872af5ab61a270cc32e4696dc678cad7e514d34c
parent9e9e028f059f29d493dc020dda965a9bea8ffd6b (diff)
fix for uninitialized value in BLI_path_cwd() if PWD wasn't defined and the CWD was longer then 160.
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h11
-rw-r--r--source/blender/blenlib/BLI_storage.h2
-rw-r--r--source/blender/blenlib/BLI_string.h2
-rw-r--r--source/blender/blenlib/BLI_utildefines.h5
-rw-r--r--source/blender/blenlib/intern/path_util.c9
-rw-r--r--source/blender/blenlib/intern/storage.c22
-rw-r--r--source/blender/blenlib/intern/string.c2
-rw-r--r--source/blender/editors/interface/interface_icons.c2
-rw-r--r--source/blender/editors/space_file/filelist.c4
9 files changed, 31 insertions, 28 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index d712a6ac2d9..2276c5ef0e6 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -59,13 +59,14 @@
#include "stdio.h" /* needed for FILE* */
#include "BLO_sys_types.h" /* needed for uintptr_t */
-#ifdef __GNUC__
-# define WARN_UNUSED __attribute__((warn_unused_result))
-#else
-# define WARN_UNUSED
+#ifndef WARN_UNUSED
+# ifdef __GNUC__
+# define WARN_UNUSED __attribute__((warn_unused_result))
+# else
+# define WARN_UNUSED
+# endif
#endif
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/source/blender/blenlib/BLI_storage.h b/source/blender/blenlib/BLI_storage.h
index 0996b19a854..702112f5fec 100644
--- a/source/blender/blenlib/BLI_storage.h
+++ b/source/blender/blenlib/BLI_storage.h
@@ -44,7 +44,7 @@ int BLI_compare(struct direntry *entry1, struct direntry *entry2);
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);
/**
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index 01ad70c31fb..1427a6c651a 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -74,7 +74,7 @@ char *BLI_strdupcat(const char *str1, const char *str2);
* 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"
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index ccda9c17d43..140b424bf8f 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -169,6 +169,11 @@
# define UNUSED(x) UNUSED_ ## x
#endif
+#ifdef __GNUC__
+# define WARN_UNUSED __attribute__((warn_unused_result))
+#else
+# define WARN_UNUSED
+#endif
/*little macro so inline keyword works*/
#if defined(_MSC_VER)
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 5d68fbe6e92..eae50b309b1 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -752,8 +752,8 @@ int BLI_path_cwd(char *path)
#endif
if (wasrelative==1) {
- char cwd[FILE_MAXDIR + FILE_MAXFILE];
- BLI_getwdN(cwd); /* incase the full path to the blend isnt used */
+ char cwd[FILE_MAXDIR + FILE_MAXFILE]= "";
+ 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 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
}
/* 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 @@ static int add_win32_extension(char *name)
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 @@ void BLI_where_am_i(char *fullname, const char *name)
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)
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index e407df7e9a1..eaa312b82f9 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -89,6 +89,7 @@
#include "BLI_listbase.h"
#include "BLI_linklist.h"
+#include "BLI_storage.h"
#include "BLI_storage_types.h"
#include "BLI_string.h"
@@ -103,20 +104,15 @@ static struct ListBase dirbase_={
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");
- if (pwd){
- strcpy(dir, pwd);
- return(dir);
- }
- /* 160 is FILE_MAXDIR in filesel.c */
- return( getcwd(dir, 160) );
+ const char *pwd= getenv("PWD");
+ if (pwd){
+ BLI_strncpy(dir, pwd, maxncpy);
+ return dir;
}
- return(0);
+
+ return getcwd(dir, maxncpy);
}
@@ -477,7 +473,7 @@ int BLI_is_dir(const char *file) {
return S_ISDIR(BLI_exist(file));
}
-LinkNode *BLI_read_file_as_lines(char *name)
+LinkNode *BLI_read_file_as_lines(const char *name)
{
FILE *fp= fopen(name, "r");
LinkNode *lines= NULL;
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 6afc34ba630..d6331d6eeb8 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -66,7 +66,7 @@ char *BLI_strdupcat(const char *str1, const char *str2)
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;
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 788de41202d..32b27874cb4 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -614,7 +614,7 @@ static void init_iconfile_list(struct ListBase *list)
/* 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 */
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index ec4733c171c..d9954b584f5 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -833,13 +833,13 @@ void filelist_setfiletypes(struct FileList* filelist)
static void filelist_read_dir(struct FileList* filelist)
{
- char wdir[FILE_MAX];
+ char wdir[FILE_MAX]= "";
if (!filelist) return;
filelist->fidx = 0;
filelist->filelist = 0;
- BLI_getwdN(wdir);
+ BLI_getwdN(wdir, sizeof(wdir)); /* backup cwd to restore after */
BLI_cleanup_dir(G.main->name, filelist->dir);
filelist->numfiles = BLI_getdir(filelist->dir, &(filelist->filelist));