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-10-20 03:10:54 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-20 03:10:54 +0400
commit5cf593a778e3dca51a5ebd6b4c23ce6c7b0a7ac6 (patch)
treed5d8889ff9dcffa4c15b7160a8850d3f16b6562e /source/blender/blenkernel/intern/packedFile.c
parent364fcde86d3cdcb09d075a0445fc2e1eb64170d5 (diff)
strcpy() --> BLI_strncpy(), where source strings are not fixed and target size is known.
Diffstat (limited to 'source/blender/blenkernel/intern/packedFile.c')
-rw-r--r--source/blender/blenkernel/intern/packedFile.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c
index 2c8975e9cb4..0041cd33c14 100644
--- a/source/blender/blenkernel/intern/packedFile.c
+++ b/source/blender/blenkernel/intern/packedFile.c
@@ -182,7 +182,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char
// convert relative filenames to absolute filenames
- strcpy(name, filename);
+ BLI_strncpy(name, filename, sizeof(name));
BLI_path_abs(name, basepath);
// open the file
@@ -240,7 +240,7 @@ void packAll(Main *bmain, ReportList *reports)
}
-/*
+#if 0
// attempt to create a function that generates an unique filename
// this will work when all funtions in fileops.c understand relative filenames...
@@ -249,6 +249,7 @@ static char *find_new_name(char *name)
{
char tempname[FILE_MAXDIR + FILE_MAXFILE];
char *newname;
+ size_t len;
if (fop_exists(name)) {
for (number = 1; number <= 999; number++) {
@@ -258,14 +259,12 @@ static char *find_new_name(char *name)
}
}
}
-
- newname = mallocN(strlen(tempname) + 1, "find_new_name");
- strcpy(newname, tempname);
-
- return(newname);
+ len= strlen(tempname) + 1;
+ newname = MEM_mallocN(len, "find_new_name");
+ memcpy(newname, tempname, len * sizeof(char));
+ return newname;
}
-
-*/
+#endif
int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, int guimode)
{
@@ -277,12 +276,12 @@ int writePackedFile(ReportList *reports, const char *filename, PackedFile *pf, i
if (guimode) {} //XXX waitcursor(1);
- strcpy(name, filename);
+ BLI_strncpy(name, filename, sizeof(name));
BLI_path_abs(name, G.main->name);
if (BLI_exists(name)) {
for (number = 1; number <= 999; number++) {
- sprintf(tempname, "%s.%03d_", name, number);
+ BLI_snprintf(tempname, sizeof(tempname), "%s.%03d_", name, number);
if (! BLI_exists(tempname)) {
if (BLI_copy_fileops(name, tempname) == RET_OK) {
remove_tmp = TRUE;
@@ -342,7 +341,7 @@ int checkPackedFile(const char *filename, PackedFile *pf)
char buf[4096];
char name[FILE_MAXDIR + FILE_MAXFILE];
- strcpy(name, filename);
+ BLI_strncpy(name, filename, sizeof(name));
BLI_path_abs(name, G.main->name);
if (stat(name, &st)) {
@@ -392,9 +391,10 @@ there was an error or when the user desides to cancel the operation.
*/
-char *unpackFile(ReportList *reports, char *abs_name, char *local_name, PackedFile *pf, int how)
+char *unpackFile(ReportList *reports, const char *abs_name, const char *local_name, PackedFile *pf, int how)
{
- char *newname = NULL, *temp = NULL;
+ char *newname = NULL;
+ const char *temp = NULL;
// char newabs[FILE_MAXDIR + FILE_MAXFILE];
// char newlocal[FILE_MAXDIR + FILE_MAXFILE];
@@ -437,12 +437,11 @@ char *unpackFile(ReportList *reports, char *abs_name, char *local_name, PackedFi
}
if (temp) {
- newname = MEM_mallocN(strlen(temp) + 1, "unpack_file newname");
- strcpy(newname, temp);
+ newname= BLI_strdup(temp);
}
}
- return (newname);
+ return newname;
}
@@ -453,17 +452,17 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how)
int ret_value = RET_ERROR;
if (vfont != NULL) {
- strcpy(localname, vfont->name);
+ BLI_strncpy(localname, vfont->name, sizeof(localname));
BLI_splitdirstring(localname, fi);
- sprintf(localname, "//fonts/%s", fi);
+ BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi);
newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(vfont->packedfile);
vfont->packedfile = NULL;
- strcpy(vfont->name, newname);
+ BLI_strncpy(vfont->name, newname, sizeof(vfont->name));
MEM_freeN(newname);
}
}
@@ -478,13 +477,13 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
int ret_value = RET_ERROR;
if (sound != NULL) {
- strcpy(localname, sound->name);
+ BLI_strncpy(localname, sound->name, sizeof(localname));
BLI_splitdirstring(localname, fi);
- sprintf(localname, "//sounds/%s", fi);
+ BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi);
newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
if (newname != NULL) {
- strcpy(sound->name, newname);
+ BLI_strncpy(sound->name, newname, sizeof(sound->name));
MEM_freeN(newname);
freePackedFile(sound->packedfile);
@@ -506,16 +505,16 @@ int unpackImage(ReportList *reports, Image *ima, int how)
int ret_value = RET_ERROR;
if (ima != NULL) {
- strcpy(localname, ima->name);
+ BLI_strncpy(localname, ima->name, sizeof(localname));
BLI_splitdirstring(localname, fi);
- sprintf(localname, "//textures/%s", fi);
-
+ BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi);
+
newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
if (newname != NULL) {
ret_value = RET_OK;
freePackedFile(ima->packedfile);
ima->packedfile = NULL;
- strcpy(ima->name, newname);
+ BLI_strncpy(ima->name, newname, sizeof(ima->name));
MEM_freeN(newname);
BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
}