Skip to content

Commit

Permalink
Increased some buffer sizes to solve #255
Browse files Browse the repository at this point in the history
  • Loading branch information
imckstewart committed Jan 15, 2018
1 parent ce183b4 commit cebf4ba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
20 changes: 10 additions & 10 deletions src/grid2fits.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ Note that data types in all capitals are defined in fitsio.h.
int status=0, colI=0, i, di, maxNumCols;
LONGLONG firstRow=1, firstElem=1;
char genericComment[80];
char genericKwd[numKwdChars], message[80];
char genericKwd[numKwdChars], message[STR_LEN_1];
char colName[numColNameChars];
char **allColNames=NULL;
int *allColNumbers=NULL, *colDataTypes=NULL;
Expand Down Expand Up @@ -615,7 +615,7 @@ Ok we have a bit of a tricky situation here in that the number of columns we wri
if(collPartNames!=NULL){
if(gridInfo.nDensities>maxNumCollPart){
if(!silent){
sprintf(message, "There seem to be %d collision partners but keywords can only be written for %d.", (int)gridInfo.nDensities, (int)maxNumCollPart);
snprintf(message, STR_LEN_1, "There seem to be %d collision partners but keywords can only be written for %d.", (int)gridInfo.nDensities, (int)maxNumCollPart);
warning(message);
}
localNumCollPart = maxNumCollPart;
Expand Down Expand Up @@ -820,7 +820,7 @@ Note that data types in all capitals are defined in fitsio.h.
const unsigned int totalNumGridPoints = gridInfo.nInternalPoints+gridInfo.nSinkPoints;
unsigned int i_ui;
int status=0, xi;
char extname[13];
char extname[STR_LEN_0];//***[13];
float *row=NULL;
int bitpix = FLOAT_IMG;
const long naxis = 2; /* i.e. 2-dimensional image */
Expand Down Expand Up @@ -895,14 +895,14 @@ countColsBasePlusInt(fitsfile *fptr, char *baseName){
/*....................................................................*/
int
countKeywords(fitsfile *fptr, char *baseName){
char kwdName[9];
char kwdName[STR_LEN_0];//***[9];
int i, status;
char kwdValue[80];
char kwdValue[STR_LEN_0];

i = 0;
status = 0;
while(!status){
sprintf(kwdName, "%s%d", baseName, i+1);
snprintf(kwdName, STR_LEN_0, "%s%d", baseName, i+1);
fits_read_key(fptr, TSTRING, kwdName, kwdValue, NULL, &status);
i++;
}
Expand All @@ -918,7 +918,7 @@ readKeywordsFromFITS(fitsfile *fptr, struct keywordType *kwds\
, const int numKeywords){

int i, status;
char message[80];
char message[STR_LEN_0];

for(i=0;i<numKeywords;i++){
status = 0;
Expand All @@ -933,7 +933,7 @@ readKeywordsFromFITS(fitsfile *fptr, struct keywordType *kwds\
fits_read_key(fptr, TDOUBLE, kwds[i].keyname, &kwds[i].doubleValue, kwds[i].comment, &status);
else{
if(!silent){
sprintf(message, "Keyword %d datatype %d is not currently accepted.", i, kwds[i].datatype);
snprintf(message, STR_LEN_0, "Keyword %d datatype %d is not currently accepted.", i, kwds[i].datatype);
bail_out(message);
}
exit(1);
Expand All @@ -960,7 +960,7 @@ Note that the calling routine needs to free gp, firstNearNeigh and collPartNames
int status=0, colNum, anynul=0, i;
char colName[20];
char genericKwd[9];
char message[80];
char message[STR_LEN_0];
unsigned int *ids=NULL;
double *xj=NULL;
_Bool *sink=NULL;/* Probably should be char* but this seems to work. */
Expand Down Expand Up @@ -1015,7 +1015,7 @@ Note that the calling routine needs to free gp, firstNearNeigh and collPartNames
*/
if(gridInfoRead->nDims!=DIM){
if(!silent){
sprintf(message, "%d Xn columns read, but there should be %d.", (int)gridInfoRead->nDims, DIM);
snprintf(message, STR_LEN_0, "%d Xn columns read, but there should be %d.", (int)gridInfoRead->nDims, DIM);
bail_out(message);
}
exit(1);
Expand Down
10 changes: 5 additions & 5 deletions src/grid_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ void checkGridDensities(configInfo *par, struct grid *gp){
/* This checks that none of the density samples is too small. */
int i;
static _Bool warningAlreadyIssued=0;
char errStr[80];
char errStr[STR_LEN_1];

if(!silent){ /* Warn if any densities too low. */
i = 0;
while(i<par->pIntensity && !warningAlreadyIssued){
if(gp[i].dens[0]<TYPICAL_ISM_DENS){
warningAlreadyIssued = 1;
sprintf(errStr, "gp[%d].dens[0] at %.1e is below typical values for the ISM (~%.1e).", i, gp[i].dens[0], TYPICAL_ISM_DENS);
snprintf(errStr, STR_LEN_1, "gp[%d].dens[0] at %.1e is below typical values for the ISM (~%.1e).", i, gp[i].dens[0], TYPICAL_ISM_DENS);
warning(errStr);
warning("This could give you convergence problems. NOTE: no further warnings will be issued.");
}
Expand Down Expand Up @@ -147,7 +147,7 @@ Elements of structs are set as follows:
facetT *facet, *neighbor, **neighborp;
int curlong, totlong;
_Bool neighbourNotFound;
char message[80];
char message[STR_LEN_1];//****[80];

/* pt_array contains the grid point locations in the format required by qhull.
*/
Expand Down Expand Up @@ -193,7 +193,7 @@ Elements of structs are set as follows:

if(gp[id].numNeigh<=0){
if(!silent){
sprintf(message, "qhull failed silently, grid point %lu has 0 neighbours. Smoother gridDensity() might help.", id);
snprintf(message, STR_LEN_1, "qhull failed silently, grid point %lu has 0 neighbours. Smoother gridDensity() might help.", id);
bail_out(message);
}
exit(1);
Expand Down Expand Up @@ -275,7 +275,7 @@ exit(1);
}
if(ffi>=(*numCells) && neighbourNotFound){
if(!silent){
sprintf(message, "Something weird going on. Cannot find a cell with ID %lu", (unsigned long)(neighbor->id));
snprintf(message, STR_LEN_1, "Something weird going on. Cannot find a cell with ID %lu", (unsigned long)(neighbor->id));
bail_out(message);
}
exit(1);
Expand Down
1 change: 1 addition & 0 deletions src/lime_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define MAX_N_COLL_PART 20
#define TYPICAL_ISM_DENS 1000.0
#define STR_LEN_0 80
#define STR_LEN_1 127
#define DENSITY_POWER 0.2
#define MAX_N_HIGH 10

Expand Down
9 changes: 6 additions & 3 deletions src/messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ goodnight(int initime){
}

void
printMessage(char message[STR_LEN_0]){
printMessage(char *message){
//printMessage(char message[STR_LEN_0]){
#ifdef NO_NCURSES
if(strlen(message)>0)
{
Expand All @@ -264,7 +265,8 @@ printMessage(char message[STR_LEN_0]){
}

void
warning(char message[STR_LEN_0]){
warning(char *message){
//warning(char message[STR_LEN_0]){
#ifdef NO_NCURSES
if(strlen(message)>0)
{
Expand All @@ -282,7 +284,8 @@ void error(char message[STR_LEN_0]){
}

void
bail_out(char message[STR_LEN_0]){
bail_out(char *message){
//bail_out(char message[STR_LEN_0]){
#ifdef NO_NCURSES
printf("Error: %s\n", message );
#else
Expand Down
36 changes: 18 additions & 18 deletions src/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ reportInfAtOrigin(const double value, const char *funcName){
void
reportInfsAtOrigin(const int numElements, const double *values, const char *funcName){
int i;
char message[STR_LEN_0];
char message[STR_LEN_1];

if(numElements<=0){
if((isinf(*values) || isnan(*values)) && !silent){
snprintf(message, STR_LEN_0, "You have a singularity at the origin of your %s() function.", funcName);
snprintf(message, STR_LEN_1, "You have a singularity at the origin of your %s() function.", funcName);
warning(message);
}
}else{
for(i=0;i<numElements;i++){
if((isinf(values[i]) || isnan(values[i])) && !silent){
snprintf(message, STR_LEN_0, "You have a singularity at the origin in return %d of your %s() function.", i, funcName);
snprintf(message, STR_LEN_1, "You have a singularity at the origin in return %d of your %s() function.", i, funcName);
warning(message);
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ The parameters visible to the user have now been strictly confined to members of
_Bool changedInterp;
int i,j,id,status=0,numGirDatFiles,numFuncDensities;
FILE *fp;
char message[STR_LEN_0];
char message[STR_LEN_1];
_Bool doThetaPhi,foundGoodValue;
double cos_pa,sin_pa,cosPhi,sinPhi,cos_incl,sin_incl,cosTheta,sinTheta,cos_az,sin_az;
double tempRotMat[3][3],auxRotMat[3][3],r[3],tempPointDensity;
Expand Down Expand Up @@ -404,7 +404,7 @@ exit(1);
for(id=0;id<par->nSpecies;id++){
if((fp=fopen(par->moldatfile[id], "r"))==NULL){
if(!silent){
snprintf(message, STR_LEN_0, "Moldat file %s not found locally - fetching it from LAMDA", par->moldatfile[id]);
snprintf(message, STR_LEN_1, "Moldat file %s not found locally - fetching it from LAMDA", par->moldatfile[id]);
printMessage(message);
}
openSocket(par->moldatfile[id]);
Expand Down Expand Up @@ -482,7 +482,7 @@ exit(1);
status = countDensityCols(par->gridInFile, &(par->numDensities));
if (status){
if(!silent){
snprintf(message, STR_LEN_0, "countDensityCols() status return %d", status);
snprintf(message, STR_LEN_1, "countDensityCols() status return %d", status);
bail_out(message);
}
exit(1);
Expand Down Expand Up @@ -656,7 +656,7 @@ The cutoff will be the value of abs(x) for which the error in the exact expressi
}
(*img)[i].imgunits[j-1] = (int)strtol(pch, &pch_end, 0);
if(*pch_end){
snprintf(message, STR_LEN_0, "Image %d: units string contains '%s' which could not be converted to an integer", i, pch_end);
snprintf(message, STR_LEN_1, "Image %d: units string contains '%s' which could not be converted to an integer", i, pch_end);
if(!silent) bail_out(message);
exit(1);
}
Expand All @@ -680,14 +680,14 @@ exit(1);

if((*img)[i].freq<0){
if(!silent){
snprintf(message, STR_LEN_0, "Image %d: you must set freq for a continuum image.", i);
snprintf(message, STR_LEN_1, "Image %d: you must set freq for a continuum image.", i);
bail_out(message);
}
exit(1);
}

if(!silent && ((*img)[i].trans>-1 || (*img)[i].bandwidth>-1.0)){
snprintf(message, STR_LEN_0, "Image %d: bandwidth and trans are ignored for a continuum image.", i);
snprintf(message, STR_LEN_1, "Image %d: bandwidth and trans are ignored for a continuum image.", i);
warning(message);
}
(*img)[i].doline=0;
Expand All @@ -705,13 +705,13 @@ The presence of one of these combinations at least is checked here, although the
*/
if((*img)[i].bandwidth > 0 && (*img)[i].velres > 0){
if(!silent && (*img)[i].nchan > 0){
snprintf(message, STR_LEN_0, "Image %d: your nchan value will be overwritten.", i);
snprintf(message, STR_LEN_1, "Image %d: your nchan value will be overwritten.", i);
warning(message);
}

}else if((*img)[i].nchan <= 0 || ((*img)[i].bandwidth <= 0 && (*img)[i].velres <= 0)) {
if(!silent){
snprintf(message, STR_LEN_0, "Image %d: insufficient info to calculate nchan, velres and bandwidth.", i);
snprintf(message, STR_LEN_1, "Image %d: insufficient info to calculate nchan, velres and bandwidth.", i);
bail_out(message);
}
exit(1);
Expand All @@ -721,20 +721,20 @@ exit(1);
*/
if((*img)[i].trans>-1){ /* => user has set trans, possibly also freq. */
if(!silent && (*img)[i].freq > 0){
snprintf(message, STR_LEN_0, "Image %d: you set trans, so I'm ignoring freq.", i);
snprintf(message, STR_LEN_1, "Image %d: you set trans, so I'm ignoring freq.", i);
warning(message);
}

if((*img)[i].molI < 0){
if(!silent && par->nSpecies>1){
snprintf(message, STR_LEN_0, "Image %d: you did not set molI, so I'm assuming the 1st molecule.", i);
snprintf(message, STR_LEN_1, "Image %d: you did not set molI, so I'm assuming the 1st molecule.", i);
warning(message);
}
(*img)[i].molI = 0;
}
}else if((*img)[i].freq<0){ /* => user has set neither trans nor freq. */
if(!silent){
snprintf(message, STR_LEN_0, "Image %d: you must set either freq or trans (plus optionally molI).", i);
snprintf(message, STR_LEN_1, "Image %d: you must set either freq or trans (plus optionally molI).", i);
bail_out(message);
}
exit(1);
Expand All @@ -745,23 +745,23 @@ exit(1);

if((*img)[i].imgres<0.0){
if(!silent){
snprintf(message, STR_LEN_0, "Image %d: you must set imgres.", i);
snprintf(message, STR_LEN_1, "Image %d: you must set imgres.", i);
bail_out(message);
}
exit(1);
}

if((*img)[i].pxls<0){
if(!silent){
snprintf(message, STR_LEN_0, "Image %d: you must set pxls.", i);
snprintf(message, STR_LEN_1, "Image %d: you must set pxls.", i);
bail_out(message);
}
exit(1);
}

if((*img)[i].distance<0.0){
if(!silent){
snprintf(message, STR_LEN_0, "Image %d: you must set distance.", i);
snprintf(message, STR_LEN_1, "Image %d: you must set distance.", i);
bail_out(message);
}
exit(1);
Expand Down Expand Up @@ -950,7 +950,7 @@ exit(1);
}else{
if((fp=fopen(par->dust, "r"))==NULL){
if(!silent){
snprintf(message, STR_LEN_0, "Couldn't open dust opacity data file %s", par->dust);
snprintf(message, STR_LEN_1, "Couldn't open dust opacity data file %s", par->dust);
bail_out(message);
}
exit(1);
Expand Down

0 comments on commit cebf4ba

Please sign in to comment.