fix indentation and add missing calloc checks
This commit is contained in:
@@ -100,19 +100,27 @@ int main(int argc, char **argv)
|
||||
exit(-1);
|
||||
}
|
||||
if (argc==2) {
|
||||
plastSlash = strrchr(argv[1],'/');
|
||||
plastSlash = (plastSlash ? plastSlash+1 : argv[1]);
|
||||
outFilename = calloc(1,strlen(plastSlash)+2);
|
||||
strcpy(outFilename,plastSlash);
|
||||
pext = strstr(outFilename,".data");
|
||||
if(!pext) {
|
||||
fprintf(stderr,"Input file MUST have .data extension\n");
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(pext,".dbd");
|
||||
plastSlash = strrchr(argv[1],'/');
|
||||
plastSlash = (plastSlash ? plastSlash+1 : argv[1]);
|
||||
outFilename = calloc(1,strlen(plastSlash)+2);
|
||||
if(!outFilename) {
|
||||
fprintf(stderr,"calloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(outFilename,plastSlash);
|
||||
pext = strstr(outFilename,".data");
|
||||
if(!pext) {
|
||||
fprintf(stderr,"Input file MUST have .data extension\n");
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(pext,".dbd");
|
||||
} else {
|
||||
outFilename = calloc(1,strlen(argv[2])+1);
|
||||
strcpy(outFilename,argv[2]);
|
||||
outFilename = calloc(1,strlen(argv[2])+1);
|
||||
if(!outFilename) {
|
||||
fprintf(stderr,"calloc failed\n");
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(outFilename,argv[2]);
|
||||
}
|
||||
inFile = fopen(argv[1],"r");
|
||||
if(!inFile) {
|
||||
@@ -126,7 +134,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
while(fgets(inbuf,MAX_LINE_SIZE,inFile)) {
|
||||
linenum++;
|
||||
inbuf[strlen(inbuf)] = '\0'; /* remove newline*/
|
||||
pbeg = inbuf;
|
||||
while(isspace((int)*pbeg) && *pbeg!= '\0') pbeg++;
|
||||
if(*pbeg == '!' || *pbeg == '\0') continue;
|
||||
@@ -138,6 +145,10 @@ int main(int argc, char **argv)
|
||||
len = pend - pbeg;
|
||||
if(len<=1) errExit("Illegal Header");
|
||||
pname = calloc(len,sizeof(char));
|
||||
if(!pname) {
|
||||
fprintf(stderr,"calloc failed while processing line %d\n",linenum);
|
||||
exit(-1);
|
||||
}
|
||||
strncpy(pname,pbeg,len);
|
||||
pbeg = pend + 1;
|
||||
if(getNumber(&pbeg,&value)) errExit("Illegal Header");
|
||||
@@ -166,11 +177,16 @@ got_header:
|
||||
while(fgets(inbuf,MAX_LINE_SIZE,inFile)) {
|
||||
double value;
|
||||
|
||||
inbuf[strlen(inbuf)] = '\0'; /* remove newline*/
|
||||
linenum++;
|
||||
pbeg = inbuf;
|
||||
while(!getNumber(&pbeg,&value)) {
|
||||
ndata++;
|
||||
pdataList = (dataList *)calloc(1,sizeof(dataList));
|
||||
if(!pdataList) {
|
||||
fprintf(stderr,"calloc failed (after header)"
|
||||
" while processing line %d\n",linenum);
|
||||
exit(-1);
|
||||
}
|
||||
if(!phead)
|
||||
phead = pdataList;
|
||||
else
|
||||
@@ -184,6 +200,10 @@ got_header:
|
||||
}
|
||||
brkCreateInfo.nTable = ndata;
|
||||
pdata = (double *)calloc(brkCreateInfo.nTable,sizeof(double));
|
||||
if(!pdata) {
|
||||
fprintf(stderr,"calloc failed for table length %d\n",brkCreateInfo.nTable);
|
||||
exit(-1);
|
||||
}
|
||||
pnext = phead;
|
||||
for(n=0; n<brkCreateInfo.nTable; n++) {
|
||||
pdata[n] = pnext->value;
|
||||
|
||||
Reference in New Issue
Block a user