diff --git a/sources/checkpoint.c b/sources/checkpoint.c index 58597d43..ce318fe8 100644 --- a/sources/checkpoint.c +++ b/sources/checkpoint.c @@ -1420,10 +1420,16 @@ int DoRecovery(int *moduletype) if ( !(fd = fopen(recoveryfile, "r")) ) return(__LINE__); /* load the complete recovery file into a buffer */ - if ( fread(&pos, sizeof(POSITION), 1, fd) != 1 ) return(__LINE__); + if ( fread(&pos, sizeof(POSITION), 1, fd) != 1 ) { + fclose(fd); + return(__LINE__); + } size = BASEPOSITION(pos) - sizeof(POSITION); buf = Malloc1(size, "recovery buffer"); - if ( fread(buf, size, 1, fd) != 1 ) return(__LINE__); + if ( fread(buf, size, 1, fd) != 1 ) { + fclose(fd); + return(__LINE__); + } /* pointer p will go through the buffer in the following */ p = buf; @@ -2478,7 +2484,7 @@ static int DoSnapshot(int moduletype) { GETIDENTITY FILE *fd; - POSITION pos; + POSITION pos = {0}; int i, j; LONG l; WORD *w; @@ -2495,10 +2501,16 @@ static int DoSnapshot(int moduletype) if ( !(fd = fopen(intermedfile, "wb")) ) return(__LINE__); /* reserve space in the file for a length field */ - if ( fwrite(&pos, 1, sizeof(POSITION), fd) != sizeof(POSITION) ) return(__LINE__); + if ( fwrite(&pos, 1, sizeof(POSITION), fd) != sizeof(POSITION) ) { + fclose(fd); + return(__LINE__); + } /* write moduletype */ - if ( fwrite(&moduletype, 1, sizeof(int), fd) != sizeof(int) ) return(__LINE__); + if ( fwrite(&moduletype, 1, sizeof(int), fd) != sizeof(int) ) { + fclose(fd); + return(__LINE__); + } /*#[ AM :*/ diff --git a/sources/minos.c b/sources/minos.c index 7a525d93..0268379f 100644 --- a/sources/minos.c +++ b/sources/minos.c @@ -622,6 +622,7 @@ DBASE *NewDbase(char *name,MLONG number) if ( ( d->iblocks = (INDEXBLOCK **)Malloc1(numblocks*sizeof(INDEXBLOCK *), "new database") ) == 0 ) { NumTableBases--; + fclose(f); return(0); } d->tablenames = 0; @@ -635,6 +636,7 @@ DBASE *NewDbase(char *name,MLONG number) "new database") ) == 0 ) { M_free(d->iblocks,"new database"); NumTableBases--; + fclose(f); return(0); } if ( ( f = fopen(name,"w+b") ) == 0 ) { diff --git a/sources/parallel.c b/sources/parallel.c index e2fd504b..39a577b5 100644 --- a/sources/parallel.c +++ b/sources/parallel.c @@ -4681,7 +4681,7 @@ static void PF_BroadcastRuntimeError(void) { assert(PF.me == MASTER); - int ret, dummy; + int ret, dummy = 0; MPI_Request requests[PF.numtasks - 1]; /* diff --git a/sources/ratio.c b/sources/ratio.c index 6c8a70bf..d63b7fad 100644 --- a/sources/ratio.c +++ b/sources/ratio.c @@ -3108,14 +3108,15 @@ char *TheErrorMessage[] = { ,"Irregular code in PolyRatFun encountered in ExpandRat." ,"Called from ExpandRat." ,"WorkSpace overflow. Change parameter WorkSpace in setup file?" + ,"Illegal term in expanded polyratfun." }; int ExpandRat(PHEAD WORD *fun) { - WORD *r, *rr, *rrr, *tt, *tnext, *arg1, *arg2, *rmin = 0, *rmininv; + WORD *r, *rr, *rrr, *tt, *tnext, *arg1, *arg2, *rmin = NULL, *rmininv; WORD *rcoef, rsize, rcopy, *ow = AT.WorkPointer; WORD *numerator, *denominator, *rnext; - WORD *thecopy, *rc, ncoef, newcoef, *m, *mm, nco, *outarg = 0; + WORD *thecopy, *rc, ncoef, newcoef, *m, *mm, nco, *outarg = NULL; UWORD co[2], co1[2], co2[2]; WORD OldPolyFunPow = AR.PolyFunPow; int i, j, minpow = 0, eppow, first, error = 0, ipoly; @@ -3127,7 +3128,7 @@ int ExpandRat(PHEAD WORD *fun) We have to normalize the argument. This could make it shorter. */ NormArg:; - if ( outarg == 0 ) outarg = TermMalloc("ExpandRat")+ARGHEAD; + if ( outarg == NULL ) outarg = TermMalloc("ExpandRat")+ARGHEAD; AT.TrimPower = 1; NewSort(BHEAD0); r = fun+FUNHEAD+ARGHEAD; @@ -3145,10 +3146,7 @@ NormArg:; if ( rrm[1] == SYMBOL && rrm[2] == 4 && rrm[3] == AR.PolyFunVar ) { if ( rrm[4] < minpow2 ) minpow2 = rrm[4]; } - else { - MesPrint("Illegal term in expanded polyratfun."); - goto onerror; - } + else { error = 5; goto onerror; } } rrm += *rrm; } @@ -3185,15 +3183,15 @@ NormArg:; First test whether we have only AR.PolyFunVar in the denominator */ tt = fun + FUNHEAD; - arg1 = arg2 = 0; + arg1 = arg2 = NULL; if ( tt < tnext ) { arg1 = tt; NEXTARG(tt); if ( tt < tnext ) { arg2 = tt; NEXTARG(tt); - if ( tt != tnext ) { arg1 = arg2 = 0; } /* more than two arguments */ + if ( tt != tnext ) { arg1 = arg2 = NULL; } /* more than two arguments */ } - } - if ( arg2 == 0 ) { + } else { error = 5; goto onerror; } + if ( arg2 == NULL ) { if ( *arg1 < 0 ) { fun[2] = CLEANFLAG; goto done; } if ( fun[2] == CLEANFLAG ) goto done; goto NormArg; /* Note: should not come here */ @@ -3201,7 +3199,7 @@ NormArg:; /* Produce the output argument in outarg */ - if ( outarg == 0 ) outarg = TermMalloc("ExpandRat")+ARGHEAD; + if ( outarg == NULL ) outarg = TermMalloc("ExpandRat")+ARGHEAD; if ( *arg2 <= 0 ) { /* @@ -3256,10 +3254,7 @@ NormArg:; if ( rrm[1] == SYMBOL && rrm[2] == 4 && rrm[3] == AR.PolyFunVar ) { if ( rrm[4] < minpow2 ) minpow2 = rrm[4]; } - else { - MesPrint("Illegal term in expanded polyratfun."); - goto onerror; - } + else { error = 5; goto onerror; } } rrm += *rrm; } @@ -3336,10 +3331,7 @@ NormArg:; if ( rrm[1] == SYMBOL && rrm[2] == 4 && rrm[3] == AR.PolyFunVar ) { if ( rrm[4] < minpow2 ) minpow2 = rrm[4]; } - else { - MesPrint("Illegal term in expanded polyratfun."); - goto onerror; - } + else { error = 5; goto onerror; } } rrm += *rrm; } diff --git a/sources/reken.c b/sources/reken.c index 902856a4..70f2cc2e 100644 --- a/sources/reken.c +++ b/sources/reken.c @@ -1246,7 +1246,7 @@ int RaisPow(PHEAD UWORD *a, WORD *na, UWORD b) c /= 2; } i--; - c = 1 << i; + c = 1u << i; while ( --i >= 0 ) { c /= 2; if(MulLong(is,ns,is,ns,it,&nt)) goto RaisOvl; diff --git a/sources/setfile.c b/sources/setfile.c index d15bb654..e8a594f0 100644 --- a/sources/setfile.c +++ b/sources/setfile.c @@ -278,11 +278,11 @@ restart:; break; case PATHVALUE: if ( StrICmp(s1,(UBYTE *)"incdir") == 0 ) { - AM.IncDir = 0; + AM.IncDir = NULL; } else if ( StrICmp(s1,(UBYTE *)"path") == 0 ) { if ( AM.Path ) M_free(AM.Path,"path"); - AM.Path = 0; + AM.Path = NULL; } else { MesPrint("Setups: %s not yet implemented",s1); @@ -775,16 +775,16 @@ int AllocSetups(void) /* And now some order sensitive things */ - if ( AM.Path == 0 ) { + if ( AM.Path == NULL ) { sp = GetSetupPar((UBYTE *)"path"); AM.Path = strDup1((UBYTE *)(sp->value),"path"); } - if ( AM.IncDir == 0 ) { + if ( AM.IncDir == NULL ) { sp = GetSetupPar((UBYTE *)"incdir"); AM.IncDir = strDup1((UBYTE *)(sp->value),"incdir"); } /* - if ( AM.TempDir == 0 ) { + if ( AM.TempDir == NULL ) { sp = GetSetupPar((UBYTE *)"tempdir"); AM.TempDir = strDup1((UBYTE *)(sp->value),"tempdir"); } diff --git a/sources/startup.c b/sources/startup.c index 6f85902d..126b7d3b 100644 --- a/sources/startup.c +++ b/sources/startup.c @@ -290,7 +290,7 @@ int DoTail(int argc, UBYTE **argv) AM.LogType = -1; AM.HoldFlag = AM.qError = AM.Interact = AM.FileOnlyFlag = 0; AM.InputFileName = AM.LogFileName = AM.IncDir = AM.TempDir = AM.TempSortDir = - AM.SetupDir = AM.SetupFile = AM.Path = 0; + AM.SetupDir = AM.SetupFile = AM.Path = NULL; AM.FromStdin = 0; /* Always use MultiRun, "-M" option is now ignored. */ AM.MultiRun = 1; @@ -538,7 +538,7 @@ printversion:; while ( *s ) *t++ = *s++; *t++ = '.'; *t++ = 'f'; *t++ = 'r'; *t++ = 'm'; *t = 0; } - if ( AM.LogType >= 0 && AM.LogFileName == 0 ) { + if ( AM.LogType >= 0 && AM.LogFileName == NULL ) { AM.LogFileName = strDup1(AM.InputFileName,"name of logfile"); s = AM.LogFileName; while ( *s ) s++; @@ -567,7 +567,7 @@ printversion:; printf("No filename specified in call of FORM\n"); errorflag++; } - if ( AM.Path == 0 ) AM.Path = (UBYTE *)getenv("FORMPATH"); + if ( AM.Path == NULL ) AM.Path = (UBYTE *)getenv("FORMPATH"); if ( AM.Path ) { /* * AM.Path is taken from argv or getenv. Reallocate it to avoid invalid @@ -718,22 +718,22 @@ void ReserveTempFiles(int par) int i = 0; WORD j; if ( par == 0 || par == 1 ) { - if ( AM.TempDir == 0 ) { + if ( AM.TempDir == NULL ) { sp = GetSetupPar((UBYTE *)"tempdir"); if ( ( sp->flags & USEDFLAG ) != USEDFLAG ) { AM.TempDir = (UBYTE *)getenv("FORMTMP"); - if ( AM.TempDir == 0 ) AM.TempDir = emptystring; + if ( AM.TempDir == NULL ) AM.TempDir = emptystring; } else AM.TempDir = (UBYTE *)(sp->value); } - if ( AM.TempSortDir == 0 ) { + if ( AM.TempSortDir == NULL ) { if ( AM.havesortdir ) { sp = GetSetupPar((UBYTE *)"tempsortdir"); AM.TempSortDir = (UBYTE *)(sp->value); } else { AM.TempSortDir = (UBYTE *)getenv("FORMTMPSORT"); - if ( AM.TempSortDir == 0 ) AM.TempSortDir = AM.TempDir; + if ( AM.TempSortDir == NULL ) AM.TempSortDir = AM.TempDir; } } /* diff --git a/sources/tools.c b/sources/tools.c index f63025b4..db2aeeeb 100644 --- a/sources/tools.c +++ b/sources/tools.c @@ -1123,6 +1123,7 @@ int CopyFile(char *source, char *dest) } out = fopen(dest, "wb"); if ( out == NULL ) { + fclose(in); perror("CopyFile: "); return(2); }