fix for possible (but unlikely) problem with strncpy not adding \0 and then extending the string with strcat. use BLI_snprintf instead.

This commit is contained in:
Campbell Barton 2011-02-12 09:58:28 +00:00
parent 5af9e5fda9
commit 3396f73c17
2 changed files with 6 additions and 11 deletions

@ -3744,8 +3744,6 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
FluidsimSettings *fss= fluidmd->fss;
ParticleSettings *part = psys->part;
ParticleData *pa=NULL;
const char *suffix = "fluidsurface_particles_####";
const char *suffix2 = ".gz";
char filename[256];
char debugStrBuffer[256];
int curFrame = sim->scene->r.cfra -1; // warning - sync with derived mesh fsmesh loading
@ -3755,14 +3753,13 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra))
// XXX if(ob==G.obedit) // off...
// return;
// ok, start loading
strcpy(filename, fss->surfdataPath);
strcat(filename, suffix);
BLI_snprintf(filename, sizeof(filename), "%sfluidsurface_particles_####.gz", fss->surfdataPath);
BLI_path_abs(filename, G.main->name);
BLI_path_frame(filename, curFrame, 0); // fixed #frame-no
strcat(filename, suffix2);
gzf = gzopen(filename, "rb");
if (!gzf) {
snprintf(debugStrBuffer,256,"readFsPartData::error - Unable to open file for reading '%s' \n", filename);

@ -85,14 +85,12 @@ static int fluidsim_find_lastframe(FluidsimSettings *fss)
char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR];
int curFrame = 1;
strncpy(targetDir, fss->surfdataPath, FILE_MAXDIR);
strcat(targetDir,"fluidsurface_final_####");
BLI_snprintf(targetDir, sizeof(targetDir), "%sfluidsurface_final_####.bobj.gz", fss->surfdataPath);
BLI_path_abs(targetDir, G.main->name);
do {
strcpy(targetFile,targetDir);
BLI_strncpy(targetFile, targetDir, sizeof(targetFile));
BLI_path_frame(targetFile, curFrame++, 0);
strcat(targetFile, ".bobj.gz");
} while(BLI_exist(targetFile));
return curFrame - 1;