Commit f4f0b769 authored by Karl Wette's avatar Karl Wette
Browse files

lalapps/src/pulsar: replace calls to sprintf() with snprintf()

parent 6f69f43d
......@@ -71,7 +71,7 @@ int main(int argc, char **argv)
/*REAL4 PWR,SNR;*/ /* 06/15/2017 gam; No longer compute SNR in this code. */
REAL4 PWR;
REAL8 f =0;
CHAR outbase[256],outfile[256],outfile2[256],outfile3[256], outfile4[256]; /*, outfile6[256]; */
CHAR outbase[256],outfile[512],outfile2[512],outfile3[512], outfile4[512]; /*, outfile6[512]; */
REAL8 NumBinsAvg =0;
REAL8 timebaseline =0;
......@@ -158,20 +158,12 @@ int main(int argc, char **argv)
if (XLALUserVarWasSet(&outputBname))
strcpy(outbase, outputBname);
else
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#if __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
#endif
sprintf(outbase, "spec_%.2f_%.2f_%s_%d_%d", f_min,f_max,constraints.detector,startTime.gpsSeconds,endTime.gpsSeconds);/*cg; this is the default name for producing the output files, the different suffixes are just added to this*/
sprintf(outfile, "%s", outbase);/*cg; name of first file to be output*/
sprintf(outfile2, "%s_timestamps", outbase);/*cg: name of second file to be output*/
/* sprintf(outfile3, "%s.txt", outbase); */ /*cg; name of third file to be output*/
sprintf(outfile3, "%s_timeaverage", outbase); /* Use the old outfile3 name from this code; python code will output the .txt version of this file. */
sprintf(outfile4, "%s_date", outbase);/*cg;file for outputting the date, which is used in matlab plotting.*/
#if __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
snprintf(outbase, sizeof(outbase), "spec_%.2f_%.2f_%s_%d_%d", f_min,f_max,constraints.detector,startTime.gpsSeconds,endTime.gpsSeconds);/*cg; this is the default name for producing the output files, the different suffixes are just added to this*/
snprintf(outfile, sizeof(outfile), "%s", outbase);/*cg; name of first file to be output*/
snprintf(outfile2, sizeof(outfile2), "%s_timestamps", outbase);/*cg: name of second file to be output*/
/* snprintf(outfile3, sizeof(outfile3), "%s.txt", outbase); */ /*cg; name of third file to be output*/
snprintf(outfile3, sizeof(outfile3), "%s_timeaverage", outbase); /* Use the old outfile3 name from this code; python code will output the .txt version of this file. */
snprintf(outfile4, sizeof(outfile4), "%s_date", outbase);/*cg;file for outputting the date, which is used in matlab plotting.*/
fp = fopen(outfile, "w");/*cg; open all three files for writing, if they don't exist create them, if they do exist overwrite them*/
fp2 = fopen(outfile2, "w");
......@@ -343,11 +335,7 @@ int main(int argc, char **argv)
char outfile5[256];
FILE *fp5 = NULL;
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
sprintf(outfile5, "%s_crab", outbase);
#pragma GCC diagnostic pop
snprintf(outfile5, sizeof(outfile5), "%s_crab", outbase);
fp5 = fopen(outfile5, "w");
/*----------------------------------------------------------------------------------------------------------------*/
......
......@@ -165,7 +165,7 @@ int main(int argc, char **argv)
REAL8 PSD, AMPPSD, PSDWT, AMPPSDWT, weight, thispower, thisavepower, scalefactor;
REAL8 PWA_TAVGWT, PWA_SUMWT;
REAL8 f = 0, f0 = 0, deltaF = 0;
CHAR outbase[256], outfile[256], outfile2[256], outfile3[256], outfile4[256] , outfile5[256];
CHAR outbase[256], outfile[512], outfile2[512], outfile3[512], outfile4[512] , outfile5[512];
// REAL8 NumBinsAvg =0;
REAL8 timebaseline = 0;
......@@ -258,21 +258,13 @@ int main(int argc, char **argv)
if (XLALUserVarWasSet(&outputBname))
strcpy(outbase, outputBname);
else
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#if __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
#endif
sprintf(outbase, "spec_%.2f_%.2f_%s_%d_%d", f_min, f_max, constraints.detector, startTime.gpsSeconds, endTime.gpsSeconds);/*cg; this is the default name for producing the output files, the different suffixes are just added to this*/
sprintf(outfile, "%s", outbase);/*cg; name of first file to be output*/
sprintf(outfile2, "%s_timestamps", outbase);/*cg: name of second file to be output*/
sprintf(outfile3, "%s.txt", outbase);/*cg; name of third file to be output*/
sprintf(outfile4, "%s_date", outbase);/*cg;file for outputting the date, which is used in matlab plotting.*/
snprintf(outbase, sizeof(outbase), "spec_%.2f_%.2f_%s_%d_%d", f_min, f_max, constraints.detector, startTime.gpsSeconds, endTime.gpsSeconds);/*cg; this is the default name for producing the output files, the different suffixes are just added to this*/
snprintf(outfile, sizeof(outfile), "%s", outbase);/*cg; name of first file to be output*/
snprintf(outfile2, sizeof(outfile2), "%s_timestamps", outbase);/*cg: name of second file to be output*/
snprintf(outfile3, sizeof(outfile3), "%s.txt", outbase);/*cg; name of third file to be output*/
snprintf(outfile4, sizeof(outfile4), "%s_date", outbase);/*cg;file for outputting the date, which is used in matlab plotting.*/
// ADDED FOR SPEC_AVG_LONG for use in cumulative plotting
sprintf(outfile5, "%s_PWA.txt", outbase);
#if __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
snprintf(outfile5, sizeof(outfile5), "%s_PWA.txt", outbase);
fp = fopen(outfile, "w");/*cg; open all three files for writing, if they don't exist create them, if they do exist overwrite them*/
fp2 = fopen(outfile2, "w");
......
......@@ -536,7 +536,7 @@ InitPFS ( ConfigVariables *cfg, UserInput_t *uvar )
{
struct tm utc;
time_t tp;
CHAR dateStr[512], line[512], summary[1024];
CHAR dateStr[512], line[1024], summary[2048];
tp = time(NULL);
sprintf (summary, "%%%% Date: %s", asctime( gmtime( &tp ) ) );
strcat (summary, "%% Loaded SFTs: [ " );
......@@ -547,15 +547,7 @@ InitPFS ( ConfigVariables *cfg, UserInput_t *uvar )
utc = *XLALGPSToUTC( &utc, (INT4)XLALGPSGetREAL8(&startTime) );
strcpy ( dateStr, asctime(&utc) );
dateStr[ strlen(dateStr) - 1 ] = 0;
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#if __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
#endif
sprintf (line, "%%%% Start GPS time tStart = %12.3f (%s GMT)\n", XLALGPSGetREAL8(&startTime), dateStr);
#if __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
snprintf (line, sizeof(line), "%%%% Start GPS time tStart = %12.3f (%s GMT)\n", XLALGPSGetREAL8(&startTime), dateStr);
strcat ( summary, line );
sprintf (line, "%%%% Total amount of data: Tdata = %12.3f s (%.2f days)\n", Tdata, Tdata/86400 );
strcat ( summary, line );
......
......@@ -316,16 +316,8 @@ int main(int argc, char **argv){
XLAL_ERROR(XLAL_EFAILED);
}
CHAR OUTFILE[256];
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#if __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
#endif
sprintf(OUTFILE, "%s/%s", inputs.outDir, out_file);
#if __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
CHAR OUTFILE[512];
snprintf(OUTFILE, sizeof(OUTFILE), "%s/%s", inputs.outDir, out_file);
if ( XLALFrameWrite(outFrame, OUTFILE)){
LogPrintf(LOG_CRITICAL, "%s : XLALFrameWrite() failed with error = %d.\n", fn, xlalErrno);
......
......@@ -144,7 +144,7 @@ int main( int argc, char *argv[] )
REAL4DemodulatedPowerVector *dmpower = NULL; /* contains the demodulated power for all SFTs */
GridParametersVector *freqgridparams = NULL; /* the coherent grid on the frequency derivitive parameter space */
GridParameters *bingridparams = NULL;
CHAR newnewtemp[LONGSTRINGLENGTH];
CHAR newnewtemp[2*LONGSTRINGLENGTH];
/* REAL8Vector *SemiCo = NULL; /\* the semi-coherent statistic results *\/ */
REAL8 fmin_read, fmax_read, fband_read; /* the range of frequencies to be read from SFTs */
UINT4 i; /* counters */
......@@ -206,26 +206,10 @@ int main( int argc, char *argv[] )
if ( mkdir( newtemp, 0755 ) != 0 && errno != EEXIST ) {
LogPrintf( LOG_DEBUG, "%s : Unable to make temporary directory %s. Might be a problem.\n", __func__, newtemp );
}
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#if __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
#endif
sprintf( newnewtemp, "%s/%.3f-%.3f", newtemp, uvar.freq, uvar.freq + uvar.freqband );
#if __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
snprintf( newnewtemp, sizeof(newnewtemp), "%s/%.3f-%.3f", newtemp, uvar.freq, uvar.freq + uvar.freqband );
} else {
/* FIXME: do not treat these format overflow warnings as errors, but do fix them later. */
#if __GNUC__ >= 8
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Wformat-overflow"
#endif
sprintf( newnewtemp, "%s/%.3f-%.3f", uvar.outputdir, uvar.freq, uvar.freq + uvar.freqband );
#if __GNUC__ >= 8
#pragma GCC diagnostic pop
#endif
snprintf( newnewtemp, sizeof(newnewtemp), "%s/%.3f-%.3f", uvar.outputdir, uvar.freq, uvar.freq + uvar.freqband );
}
/* make frequency+band directory inside output/temporary directory */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment