Commit 25213515 authored by Kipp Cannon's avatar Kipp Cannon

lalapps/src/inspiral memory fixes

- fix memory bugs identified by gcc 8 in lalapps/src/inspiral/
- without this patch lalapps is uncompilable with an up-to-date gcc and -Werror
parent b8890249
......@@ -179,7 +179,7 @@ ProcessParamsTable *next_process_param(
snprintf( pp->param, LIGOMETA_PARAM_MAX, "-userTag" );
else
snprintf( pp->param, LIGOMETA_PARAM_MAX, "--%s", name );
strncpy( pp->type, type, LIGOMETA_TYPE_MAX );
strncpy( pp->type, type, LIGOMETA_TYPE_MAX - 1 );
va_start( ap, fmt );
vsnprintf( pp->value, LIGOMETA_VALUE_MAX, fmt, ap );
va_end( ap );
......
......@@ -110,7 +110,6 @@ int main(int argc, char *argv[])
LALStatus status=blank_status;
CHAR inputfile[FILENAME_MAX];
CHAR outputpath[1000];
CHAR adjustedfile[FILENAME_MAX+10];
CHAR injtype[30];
CHAR det_name[10];
INT8 detectorFlags;
......@@ -526,8 +525,8 @@ int main(int argc, char *argv[])
MDT.simInspiralTable = headTable;
fprintf(stderr,"Overwriting %s with adjusted distances\n",inputfile);
strncat(adjustedfile,inputfile,strlen(inputfile)-4); /* Cut off the .xml */
sprintf(inputfile,"%s_adj.xml",adjustedfile);
inputfile[strlen(inputfile)-4] = 0; /* Cut off the .xml */
strncat(inputfile,"_adj.xml",FILENAME_MAX-1);
xmlfp=XLALOpenLIGOLwXMLFile((const char *)inputfile);
if(xmlfp==NULL) fprintf(stderr,"Error! Cannot open %s for writing\n",inputfile);
LAL_CALL( LALBeginLIGOLwXMLTable( &status, xmlfp, sim_inspiral_table ), &status );
......
......@@ -872,13 +872,15 @@ int main( int argc, char *argv[] )
if( userTag )
{
snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.gwf", outfileName,
userTag, output.epoch.gpsSeconds, frameLength );
if(snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.gwf", outfileName,
userTag, output.epoch.gpsSeconds, frameLength ) >= FILENAME_MAX)
abort();
}
else
{
snprintf( fname, FILENAME_MAX, "%s-%d-%d.gwf", outfileName,
output.epoch.gpsSeconds, frameLength );
if(snprintf( fname, FILENAME_MAX, "%s-%d-%d.gwf", outfileName,
output.epoch.gpsSeconds, frameLength ) >= FILENAME_MAX)
abort();
}
if ( vrbflg ) fprintf( stdout, "writing frame data to %s... ", fname );
......@@ -912,28 +914,31 @@ int main( int argc, char *argv[] )
memset( &results, 0, sizeof(LIGOLwXMLStream) );
if( userTag && outCompress )
{
snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.xml.gz", outfileName,
if(snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.xml.gz", outfileName,
userTag, gpsStartTime.gpsSeconds,
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds );
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
abort();
}
else if( userTag && !outCompress )
{
snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.xml", outfileName,
if(snprintf( fname, FILENAME_MAX, "%s_%s-%d-%d.xml", outfileName,
userTag, gpsStartTime.gpsSeconds,
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds );
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
abort();
}
else if( !userTag && outCompress )
{
snprintf( fname, FILENAME_MAX, "%s-%d-%d.xml.gz", outfileName,
if(snprintf( fname, FILENAME_MAX, "%s-%d-%d.xml.gz", outfileName,
gpsStartTime.gpsSeconds,
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds );
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
abort();
}
else
{
snprintf( fname, FILENAME_MAX, "%s-%d-%d.xml", outfileName,
if(snprintf( fname, FILENAME_MAX, "%s-%d-%d.xml", outfileName,
gpsStartTime.gpsSeconds,
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds );
gpsEndTime.gpsSeconds - gpsStartTime.gpsSeconds ) >= FILENAME_MAX)
abort();
}
if ( vrbflg ) fprintf( stdout, "writing XML data to %s...\n", fname );
......
......@@ -539,7 +539,6 @@ INT4 pntMass2=1;
REAL4 deltaMass1=-1;
REAL4 deltaMass2=-1;
INT4 bandPassInj = 0;
INT4 writeSimRing = 0;
LALSimInspiralApplyTaper taperInj = LAL_SIM_INSPIRAL_TAPER_NONE;
AlignmentType alignInj = notAligned;
REAL8 redshift;
......@@ -933,7 +932,7 @@ ProcessParamsTable *next_process_param( const char *name, const char *type,
}
strncpy( pp->program, PROGRAM_NAME, LIGOMETA_PROGRAM_MAX );
snprintf( pp->param, LIGOMETA_PARAM_MAX, "--%s", name );
strncpy( pp->type, type, LIGOMETA_TYPE_MAX );
strncpy( pp->type, type, LIGOMETA_TYPE_MAX - 1 );
va_start( ap, fmt );
vsnprintf( pp->value, LIGOMETA_VALUE_MAX, fmt, ap );
va_end( ap );
......@@ -1111,9 +1110,6 @@ static void print_usage(char *program)
" [--taper-injection] OPT Taper the inspiral template using option OPT\n"\
" (start|end|startend) \n"\
" [--band-pass-injection] sets the tapering method of the injected waveform\n\n");
fprintf(stderr,
"Output:\n"\
" [--write-sim-ring] Writes a sim_ringdown table\n\n");
}
......@@ -1454,7 +1450,7 @@ sourceComplete()
/* Other Variables */
int edgenum = (int) ceil((M_min-M_max)/edgestep); /* Number of magnitude bins */
char galaxyname[LIGOMETA_SOURCE_MAX] = "Fake"; /* Beginning of name for all added (non-real) galaxies */
const char *galaxyname = "Fake"; /* Beginning of name for all added (non-real) galaxies */
int distnum = (maxDistance-initDistance)/DeltaD; /* Number of elements in Distance vector */
int k_at_25Mpc = floor((25000-initDistance)/DeltaD); /* Initial index for Distance vector - no galaxies added before 25Mpc */
int j,k,q; /* Indices for loops */
......@@ -2020,7 +2016,6 @@ int main( int argc, char *argv[] )
{"write-compress", no_argument, &outCompress, 1},
{"taper-injection", required_argument, 0, '*'},
{"band-pass-injection", no_argument, 0, '}'},
{"write-sim-ring", no_argument, 0, '{'},
{"ipn-file", required_argument, 0, '^'},
{"spin-gaussian", no_argument, 0, 1002},
{"stdev-spin1", required_argument, 0, 1003},
......@@ -3115,14 +3110,6 @@ int main( int argc, char *argv[] )
bandPassInj = 1;
break;
case '{':
/* write out a sim_ringdown table */
this_proc_param = this_proc_param->next =
next_process_param( long_options[option_index].name, "string",
"" );
writeSimRing = 1;
break;
case '*':
/* Set injection tapering */
if ( ! strcmp( "start", LALoptarg ) )
......@@ -4442,43 +4429,6 @@ int main( int argc, char *argv[] )
simTable->bandpass = bandPassInj;
/* populate the sim_ringdown table */
if ( writeSimRing )
{
memcpy( simRingTable->waveform, "Ringdown",
sizeof(CHAR) * LIGOMETA_WAVEFORM_MAX );
memcpy( simRingTable->coordinates, "EQUATORIAL",
sizeof(CHAR) * LIGOMETA_COORDINATES_MAX );
simRingTable->geocent_start_time = simTable->geocent_end_time;
simRingTable->h_start_time = simTable->h_end_time;
simRingTable->l_start_time = simTable->l_end_time;
simRingTable->v_start_time = simTable->v_end_time;
simRingTable->start_time_gmst = simTable->end_time_gmst;
simRingTable->longitude = simTable->longitude;
simRingTable->latitude = simTable->latitude;
simRingTable->distance = simTable->distance;
simRingTable->inclination = simTable->inclination;
simRingTable->polarization = simTable->polarization;
simRingTable->phase = 0;
simRingTable->mass = XLALNonSpinBinaryFinalBHMass(simTable->eta, simTable->mass1, simTable->mass2);
/* The final spin calc has been generalized so as to allow initially spinning systems*/
/* simRingTable->spin = XLALNonSpinBinaryFinalBHSpin(simTable->eta); */
simRingTable->spin = XLALSpinBinaryFinalBHSpin(simTable->eta, simTable->mass1, simTable->mass2,
simTable->spin1x, simTable->spin2x,simTable->spin1y, simTable->spin2y, simTable->spin1z, simTable->spin2z);
simRingTable->frequency = XLALBlackHoleRingFrequency( simRingTable->mass, simRingTable->spin);
simRingTable->quality = XLALBlackHoleRingQuality(simRingTable->spin);
simRingTable->epsilon = 0.01;
simRingTable->amplitude = XLALBlackHoleRingAmplitude( simRingTable->frequency, simRingTable->quality, simRingTable->distance, simRingTable->epsilon );
simRingTable->eff_dist_h = simTable->eff_dist_h;
simRingTable->eff_dist_l = simTable->eff_dist_l;
simRingTable->eff_dist_v = simTable->eff_dist_v;
simRingTable->hrss = XLALBlackHoleRingHRSS( simRingTable->frequency, simRingTable->quality, simRingTable->amplitude, 2., 0. );
// need hplus & hcross in each detector to populate these
simRingTable->hrss_h = 0.; //XLALBlackHoleRingHRSS( simRingTable->frequency, simRingTable->quality, simRingTable->amplitude, 0., 0. );
simRingTable->hrss_l = 0.; //XLALBlackHoleRingHRSS( simRingTable->frequency, simRingTable->quality, simRingTable->amplitude, 0., 0. );
simRingTable->hrss_v = 0.; //XLALBlackHoleRingHRSS( simRingTable->frequency, simRingTable->quality, simRingTable->amplitude, 0., 0. );
}
/* increment current time, avoiding roundoff error;
check if end of loop is reached */
if (tDistr == LALINSPIRAL_EXPONENTIAL_TIME_DIST)
......@@ -4557,18 +4507,6 @@ int main( int argc, char *argv[] )
LAL_CALL( LALEndLIGOLwXMLTable ( &status, &xmlfp ), &status );
}
if ( writeSimRing )
{
if ( ringparams.simRingdownTable )
{
LAL_CALL( LALBeginLIGOLwXMLTable( &status, &xmlfp, sim_ringdown_table ),
&status );
LAL_CALL( LALWriteLIGOLwXMLTable( &status, &xmlfp, ringparams,
sim_ringdown_table ), &status );
LAL_CALL( LALEndLIGOLwXMLTable ( &status, &xmlfp ), &status );
}
}
LAL_CALL( LALCloseLIGOLwXMLFile ( &status, &xmlfp ), &status );
if (source_data)
......
......@@ -204,7 +204,7 @@ static ProcessParamsTable *next_process_param( const char *name, const char *typ
}
strncpy( pp->program, PROGRAM_NAME, LIGOMETA_PROGRAM_MAX );
snprintf( pp->param, LIGOMETA_PARAM_MAX, "--%s", name );
strncpy( pp->type, type, LIGOMETA_TYPE_MAX );
strncpy( pp->type, type, LIGOMETA_TYPE_MAX - 1 );
va_start( ap, fmt );
vsnprintf( pp->value, LIGOMETA_VALUE_MAX, fmt, ap );
va_end( ap );
......
......@@ -463,7 +463,7 @@ int main ( int argc, char *argv[] )
memcpy( bankFileNameHead, bankFileName,
(size_t) gpsHyphen - (size_t) bankFileName < FILENAME_MAX ?
(gpsHyphen - bankFileName) * sizeof(CHAR) : FILENAME_MAX * sizeof(CHAR) );
strncpy( bankFileNameTail, gpsHyphen + 1, FILENAME_MAX );
strncpy( bankFileNameTail, gpsHyphen + 1, FILENAME_MAX - 1 );
if ( vrbflg )
{
......@@ -489,8 +489,9 @@ int main ( int argc, char *argv[] )
{
/* open the output xml file */
memset( outBankFileName, 0, FILENAME_MAX * sizeof(CHAR) );
snprintf( outBankFileName, FILENAME_MAX, "%s_%2.2d-%s",
bankFileNameHead, i, bankFileNameTail );
if(snprintf( outBankFileName, FILENAME_MAX, "%s_%02d-%s",
bankFileNameHead, i, bankFileNameTail ) >= FILENAME_MAX)
abort();
memset( &xmlStream, 0, sizeof(LIGOLwXMLStream) );
LAL_CALL( LALOpenLIGOLwXMLFile( &status , &xmlStream, outBankFileName),
&status );
......
......@@ -371,13 +371,13 @@ int main( int argc, char *argv[] )
case 'a':
/* name of input ifo*/
strncpy( inputIFO, LALoptarg, LIGOMETA_IFO_MAX );
strncpy( inputIFO, LALoptarg, LIGOMETA_IFO_MAX - 1 );
ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
break;
case 'b':
/* name of output ifo */
strncpy( outputIFO, LALoptarg, LIGOMETA_IFO_MAX );
strncpy( outputIFO, LALoptarg, LIGOMETA_IFO_MAX - 1 );
ADD_PROCESS_PARAM( "string", "%s", LALoptarg );
break;
......
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