forked from bartvdbraak/blender
fix for uninitialized value in BLI_path_cwd() if PWD wasn't defined and the CWD was longer then 160.
This commit is contained in:
parent
9e9e028f05
commit
6e47ffcc0d
@ -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
|
||||
|
@ -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);
|
||||
/**
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user