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 /source/blender/blenlib
parent9e9e028f059f29d493dc020dda965a9bea8ffd6b (diff)
fix for uninitialized value in BLI_path_cwd() if PWD wasn't defined and the CWD was longer then 160.
Diffstat (limited to 'source/blender/blenlib')
-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
6 files changed, 22 insertions, 20 deletions
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;