Commit 074f8085 authored by Benoit Mours's avatar Benoit Mours
Browse files

Fix some functions that were not thread safe

parent 305d4a61
Pipeline #173187 passed with stages
in 2 minutes and 2 seconds
......@@ -4979,21 +4979,22 @@ char *FrError(int level,
{static int errorMsgL = 0;
#define FRERRORMSGSIZE 500 /* this is used only in this function */
static char errorMsg[FRERRORMSGSIZE];
char buf[256];
if(level == -1) return(errorMsg);
 
if(level < 2)
{sprintf(FrBuf," *** FrInfo: in %s %s\n",function,message);}
{snprintf(buf, 256, " *** FrInfo: in %s %s\n",function,message);}
else if(level < 3)
{sprintf(FrBuf," *** FrWarning: in %s %s\n",function,message);}
else{sprintf(FrBuf," *** FrError: in %s %s\n",function,message);}
{snprintf(buf, 256, " *** FrWarning: in %s %s\n",function,message);}
else{snprintf(buf, 256, " *** FrError: in %s %s\n",function,message);}
if(errorMsgL < FRERRORMSGSIZE)
{strncpy(&errorMsg[errorMsgL], FrBuf, FRERRORMSGSIZE-errorMsgL);
errorMsgL = strlen(FrBuf) + errorMsgL;}
{strncpy(&errorMsg[errorMsgL], buf, FRERRORMSGSIZE-errorMsgL);
errorMsgL = strlen(buf) + errorMsgL;}
if(FrErrorHandler != NULL)
{FrErrorHandler(level, FrBuf);}
{FrErrorHandler(level, buf);}
return(errorMsg);}
 
......@@ -6069,6 +6070,7 @@ FrFile *FrFileNew(const char *fileName,
/*---------------------------------------------------------------------------*/
{FrFile *file;
FrFileH *fileH;
char version[256];
int i;
FrLibShortIni(); /*---- do a short init if needed ---*/
......@@ -6138,8 +6140,8 @@ FrFile *FrFileNew(const char *fileName,
 
/*----------------- default history message ----*/
 
sprintf(FrBuf,"FrameLib:%s (comp:%s)",FR_VERSION, __DATE__);
FrStrCpy(&(file->historyMsg), FrBuf);
snprintf(version,256,"FrameLib:%s (comp:%s)",FR_VERSION, __DATE__);
FrStrCpy(&(file->historyMsg), version);
/*---- reset dictionary output ----*/
for(i=0; i<FRMAPMAXSH; i++)
......@@ -8093,14 +8095,15 @@ FrFile *FrFileONewH(const char *fileName,
const char *program)
/*---------------------------------------------------------------------------*/
{FrFile *oFile;
char version[256];
 
oFile = FrFileONew(fileName, compress);
if(oFile == NULL) return(NULL);
 
if(program != NULL) {
free(oFile->historyMsg);
sprintf(FrBuf,"FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, FrBuf) == NULL) return (NULL);}
snprintf(version, 256, "FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, version) == NULL) return (NULL);}
 
return(oFile);}
 
......@@ -8111,6 +8114,7 @@ FrFile *FrFileONewM(const char *path,
int fLength)
/*---------------------------------------------------------------------------*/
{FrFile *oFile;
char version[256];
 
oFile = (FrFile *) calloc(sizeof(FrFile), 1);
if(oFile == NULL) return(NULL);
......@@ -8126,8 +8130,8 @@ FrFile *FrFileONewM(const char *path,
oFile->chkSumFiFlag = FR_YES;
 
if(program != NULL) {
sprintf(FrBuf,"FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, FrBuf) == NULL) return (NULL);}
snprintf(version, 256, "FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, version) == NULL) return (NULL);}
 
return(oFile);}
 
......@@ -8141,6 +8145,7 @@ FrFile *FrFileONewMD(const char* path,
/*---------------------------------------------------------------------------*/
{
FrFile *oFile;
char version[256];
 
oFile = (FrFile *) calloc(sizeof(FrFile), 1);
if(oFile == NULL) return(NULL);
......@@ -8154,8 +8159,8 @@ FrFile *FrFileONewMD(const char* path,
oFile->dirPeriod = dirPeriod;
 
if(program != NULL) {
sprintf(FrBuf,"FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, FrBuf) == NULL) return (NULL);}
snprintf(version, 256, "FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, version) == NULL) return (NULL);}
 
return(oFile);}
 
......@@ -8165,14 +8170,15 @@ FrFile *FrFileONewFdH(FrIO *frfd,
const char *program)
/*---------------------------------------------------------------------------*/
{FrFile *oFile;
char version[256];
 
oFile = FrFileONewFd(frfd, compress);
if(oFile == NULL) return(NULL);
 
if(program != NULL) {
free(oFile->historyMsg);
sprintf(FrBuf,"FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, FrBuf) == NULL) return (NULL);}
snprintf(version, 256, "FrameLib:%s %s",FR_VERSION, program);
if(FrStrCpy(&oFile->historyMsg, version) == NULL) return (NULL);}
 
return(oFile);}
 
......@@ -8225,7 +8231,7 @@ FrFileH* FrFileOpenCacheFile(const char *fullName)
FrFileH *fileH, *fileHFirst, *fileHLast;
FILE *fp;
int length, i;
char *p;
char word[512], *p;
 
fp = fopen(fullName,"r");
if(fp == NULL){
......@@ -8235,10 +8241,10 @@ FrFileH* FrFileOpenCacheFile(const char *fullName)
fileHFirst = NULL;
fileHLast = NULL;
 
while(fscanf(fp,"%s",FrBuf) == 1) {
while(fscanf(fp,"%s",word) == 1) {
 
if(strncmp(FrBuf,"file:",5) == 0) p = FrBuf+5; /*--search for the file name-*/
else p = FrBuf;
if(strncmp(word,"file:",5) == 0) p = word+5; /*--search for the file name-*/
else p = word;
 
fileH = (FrFileH *) calloc(sizeof(FrFileH),1);
if(fileH == NULL) return(NULL);
......@@ -8282,7 +8288,7 @@ FrFileH** FrFileOpenFFL(const char *fullName,
/* We assume the ffl contains only one file per line */
/*---------------------------------------------------------------------------*/
{FrFileH *fileH;
char *start, *end;
char *start, *end, line[512];
FILE *fp;
const char whitespace[] = " \f\n\r\t\v";
int nRead;
......@@ -8293,8 +8299,8 @@ FrFileH** FrFileOpenFFL(const char *fullName,
return(NULL);}
 
/*----------------------------------------------process file line by line---*/
while(fgets(FrBuf, FrBufSize, fp) != NULL) {
start = FrBuf + strspn(FrBuf, whitespace);
while(fgets(line, 512, fp) != NULL) {
start = line + strspn(line, whitespace);
if(start[0] == '#') continue; /*-----------------------skip comments---*/
 
if(start[0] == 'S') { /*-------------------read segment list---*/
......@@ -8470,14 +8476,16 @@ void FrFileOSetGzipLevel(FrFile *oFile, unsigned short level)
void FrFileOSetMsg(FrFile *oFile, char *msg)
/*---------------------------------------------------------------------------*/
{
char version[256];
if(oFile == NULL) return;
 
free(oFile->historyMsg);
oFile->historyMsg = NULL;
 
if(msg != NULL) {
sprintf(FrBuf,"FrameLib:%s %s",FR_VERSION, msg);
FrStrCpy(&oFile->historyMsg, FrBuf);}
snprintf(version, 256, "FrameLib:%s %s",FR_VERSION, msg);
FrStrCpy(&oFile->historyMsg, version);}
 
return;}
 
......@@ -16662,6 +16670,7 @@ FrVect *FrVectConcat(FrVect *vectIn, double tStart, double len)
FRBOOL isAux;
FRULONG nDataTime, i, type, wSize, blockSize, gtime;
double dt, dO, start;
char name[256];
 
if(vectIn == NULL) return(NULL);
 
......@@ -16745,8 +16754,8 @@ FrVect *FrVectConcat(FrVect *vectIn, double tStart, double len)
if(vect->nDim > 1) {output->startX[1] = vect->startX[1];}
if(vect->nDim > 2) {output->startX[2] = vect->startX[2];}
 
sprintf(FrBuf,"Available_data_for_%s",vect->name);
isThere = FrVectNew1D(FrBuf, FR_VECT_C, nDataTime, dt,
snprintf(name, 256, "Available_data_for_%s",vect->name);
isThere = FrVectNew1D(name, FR_VECT_C, nDataTime, dt,
vect->unitX[0], "1 if data is there");
if(isThere == NULL) return(NULL);
isThere->GTime = tStart;
......@@ -19751,6 +19760,7 @@ FrVect *FrVectReshapeNew(FrVect *vect,
{FrVect *output, *isThere;
FRULONG nData, i;
double rounding = 1.e-6; /*----- used to avoid rounding problems */
char name[256];
 
/*-------------------- create the output vectors -----------------*/
 
......@@ -19762,8 +19772,8 @@ FrVect *FrVectReshapeNew(FrVect *vect,
output->localTime= vect->localTime;
output->ULeapS = vect->ULeapS;
 
sprintf(FrBuf,"Available_data_for_%s",vect->name);
isThere = FrVectNew1D(FrBuf, FR_VECT_C, nData, vect->dx[0],
snprintf(name, 256, "Available_data_for_%s",vect->name);
isThere = FrVectNew1D(name, FR_VECT_C, nData, vect->dx[0],
vect->unitX[0], "1 if data is there");
if(isThere == NULL) return(NULL);
output->next = isThere;
......
Supports Markdown
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