diff --git a/configure.ac b/configure.ac index 9aaf51cc2..a8c1549aa 100644 --- a/configure.ac +++ b/configure.ac @@ -1333,4 +1333,9 @@ else AC_SUBST([CMPP], ['$(top_builddir)/src/xspice/cmpp/cmpp$(EXEEXT)']) fi +# See https://github.com/kimwalisch/primesieve/issues/16 +# Silence warning: ar: 'u' modifier ignored since 'D' is the default +AC_SUBST(AR_FLAGS, [cr]) + + AC_OUTPUT diff --git a/src/ciderlib/input/dopset.c b/src/ciderlib/input/dopset.c index d543713fb..ad69fe23e 100644 --- a/src/ciderlib/input/dopset.c +++ b/src/ciderlib/input/dopset.c @@ -4,18 +4,19 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group Modifed: 2001 Paolo Nenzi **********/ -#include "ngspice/ngspice.h" +#include "ngspice/carddefs.h" +#include "ngspice/cidersupt.h" #include "ngspice/cktdefs.h" -#include "ngspice/numenum.h" +#include "ngspice/ciderinp.h" +#include "ngspice/cpextern.h" #include "ngspice/dopdefs.h" #include "ngspice/meshext.h" +#include "ngspice/ngspice.h" +#include "ngspice/numenum.h" #include "ngspice/profile.h" #include "ngspice/gendev.h" #include "ngspice/sperror.h" #include "ngspice/suffix.h" -#include "ngspice/cidersupt.h" -#include "ngspice/carddefs.h" -#include "ngspice/ciderinp.h" /* @@ -234,17 +235,29 @@ DOPsetup(DOPcard *cardList, DOPprofile **profileList, DOPtable **tableList, break; case DOP_SUPREM3: newProfile->type = LOOKUP; - readSupremData( card->DOPinFile, 0, card->DOPimpurityType, tableList ); + if (readSupremData( card->DOPinFile, 0, card->DOPimpurityType, + tableList) != 0) { + (void) fprintf(cp_err, "Doping setup failed.\n"); + return -1; + } newProfile->IMPID = ++impurityId; break; case DOP_SUPASCII: newProfile->type = LOOKUP; - readSupremData( card->DOPinFile, 1, card->DOPimpurityType, tableList ); + if (readSupremData( card->DOPinFile, 1, card->DOPimpurityType, + tableList) != 0) { + (void) fprintf(cp_err, "Doping setup failed.\n"); + return -1; + } newProfile->IMPID = ++impurityId; break; case DOP_ASCII: newProfile->type = LOOKUP; - readAsciiData( card->DOPinFile, card->DOPimpurityType, tableList ); + if (readAsciiData(card->DOPinFile, card->DOPimpurityType, + tableList) != 0) { + (void) fprintf(cp_err, "Doping setup failed.\n"); + return -1; + } newProfile->IMPID = ++impurityId; break; default: diff --git a/src/ciderlib/oned/oneadmit.c b/src/ciderlib/oned/oneadmit.c index 9920a2f55..13df2f602 100644 --- a/src/ciderlib/oned/oneadmit.c +++ b/src/ciderlib/oned/oneadmit.c @@ -40,7 +40,7 @@ NUMDadmittance(ONEdevice *pDevice, double omega, SPcomplex *yd) int index, i; double yReal, yImag; double *solutionReal, *solutionImag; - SPcomplex yAc, cOmega; + SPcomplex yAc_adm, cOmega; SPcomplex *y; BOOLEAN SORFailed; double startTime; @@ -146,13 +146,13 @@ NUMDadmittance(ONEdevice *pDevice, double omega, SPcomplex *yd) startTime = SPfrontEnd->IFseconds(); pNode = pDevice->elemArray[1]->pLeftNode; y = computeAdmittance(pNode, FALSE, solutionReal, solutionImag, &cOmega); - CMPLX_ASSIGN_VALUE(yAc, -y->real, -y->imag); - CMPLX_ASSIGN(*yd, yAc); + CMPLX_ASSIGN_VALUE(yAc_adm, -y->real, -y->imag); + CMPLX_ASSIGN(*yd, yAc_adm); CMPLX_MULT_SELF_SCALAR(*yd, GNorm * pDevice->area); pDevice->pStats->miscTime[STAT_AC] += SPfrontEnd->IFseconds() - startTime; return (AcAnalysisMethod); -} +} /* end of function NUMDadmittance */ int diff --git a/src/ciderlib/oned/onedopng.c b/src/ciderlib/oned/onedopng.c index 24d6e0322..ab0fc4ca9 100644 --- a/src/ciderlib/oned/onedopng.c +++ b/src/ciderlib/oned/onedopng.c @@ -77,6 +77,7 @@ ONEdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x) } else { value = pProfile->PEAK_CONC * exp(-argP); } + break; case EXP: argP = ABS(argP); if (argP > 80.0) { diff --git a/src/ciderlib/support/suprem.c b/src/ciderlib/support/suprem.c index 7aded0e3b..bd6cc572b 100644 --- a/src/ciderlib/support/suprem.c +++ b/src/ciderlib/support/suprem.c @@ -5,26 +5,36 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group **********/ /* Functions to read SUPREM (Binary or Ascii) & ASCII input files */ +#include +#include +#include "ngspice/cidersupt.h" +#include "ngspice/cpextern.h" #include "ngspice/ngspice.h" #include "ngspice/profile.h" -#include "ngspice/cidersupt.h" -void -readAsciiData( char *fileName, int impType, DOPtable **ppTable ) + +static void free_profile_data(double **p); +static double **alloc_profile_data(size_t n); + + +int readAsciiData(const char *fileName, int impType, DOPtable **ppTable) { - FILE *fpAscii; + int xrc = 0; + FILE *fpAscii = (FILE *) NULL; int index; double x, y; int numPoints; - DOPtable *tmpTable; - double **profileData; + DOPtable *tmpTable = (DOPtable *) NULL; + double **profileData = (double **) NULL; double sign; /* Open Input File */ if ((fpAscii = fopen( fileName, "r" )) == NULL) { - perror( fileName ); - exit(-1); + (void) fprintf(cp_err, "unable to open SUPREM file \"%s\": %s\n", + fileName, strerror(errno)); + xrc = -1; + goto EXITPOINT; } /* Get sign of concentrations */ @@ -35,31 +45,43 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable ) } /* read the number of points */ - fscanf( fpAscii, "%d", &numPoints ); + if (fscanf(fpAscii, "%d", &numPoints) != 1) { + (void) fprintf(cp_err, "unable to read point count " + "from SUPREM file \"%s\"\n", + fileName); + xrc = -1; + goto EXITPOINT; + } + /* allocate 2-D array to read in data of x-coordinate and N(x) */ - XCALLOC( profileData, double *, 2 ); - for( index = 0; index <= 1; index++ ) { - XCALLOC( profileData[ index ], double, 1 + numPoints ); - } + profileData = alloc_profile_data((size_t) numPoints + 1); + /* the number of points is stored as profileData[0][0] */ profileData[0][0] = numPoints; - for( index = 1; index <= numPoints; index++ ) { - fscanf( fpAscii, "%lf %lf ", &x, &y ); - profileData[ 0 ][ index ] = x; - profileData[ 1 ][ index ] = sign * ABS(y); - } + for (index = 1; index <= numPoints; index++ ) { + if (fscanf(fpAscii, "%lf %lf ", &x, &y) != 2) { + (void) fprintf(cp_err, "unable to read point %d" + "from SUPREM file \"%s\"\n", + index + 1, fileName); + xrc = -1; + goto EXITPOINT; + } + profileData[0][index] = x; + profileData[1][index] = sign * ABS(y); + } /* end of loop over points */ /* Now create a new lookup table */ - XCALLOC( tmpTable, DOPtable, 1 ); - if ( *ppTable == NULL ) { + XCALLOC(tmpTable, DOPtable, 1); + if (*ppTable == NULL) { /* First Entry */ tmpTable->impId = 1; tmpTable->dopData = profileData; tmpTable->next = NULL; *ppTable = tmpTable; - } else { + } + else { tmpTable->impId = (*ppTable)->impId + 1; tmpTable->dopData = profileData; tmpTable->next = *ppTable; @@ -72,9 +94,21 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable ) printf("\n %e %e", profileData[ 0 ][ index ], profileData[ 1 ][ index ]); } */ - fclose(fpAscii); - return; -} +EXITPOINT: + if (fpAscii != (FILE *) NULL) { /* close data file if open */ + fclose(fpAscii); + } + + /* Free resources on error */ + if (xrc != 0) { + free_profile_data(profileData); + free(tmpTable); + } + + return xrc; +} /* end of function readAsciiData */ + + /* interface routine based on notes provided by Steve Hansen of Stanford */ @@ -108,40 +142,45 @@ readAsciiData( char *fileName, int impType, DOPtable **ppTable ) */ -void -readSupremData(char *fileName, int fileType, int impType, DOPtable **ppTable) +int readSupremData(const char *fileName, int fileType, int impType, + DOPtable **ppTable) { + int xrc = 0; #define MAX_GRID 500 float x[ MAX_GRID ], conc[ MAX_GRID ]; int index; - DOPtable *tmpTable; - double **profileData; + DOPtable *tmpTable = (DOPtable *) NULL; + double **profileData = (double **) NULL; int numNodes; /* read the Suprem data file */ if ( fileType == 0 ) { /* BINARY FILE */ - SUPbinRead( fileName, x, conc, &impType, &numNodes ); + const int rc = SUPbinRead(fileName, x, conc, &impType, + &numNodes); + if (rc != 0) { + (void) fprintf(cp_err, "Data input failed.\n"); + xrc = -1; + goto EXITPOINT; + } } else { SUPascRead( fileName, x, conc, &impType, &numNodes ); } /* allocate 2-D array to read in data of x-coordinate and N(x) */ - XCALLOC( profileData, double *, 2 ); - for( index = 0; index <= 1; index++ ) { - XCALLOC( profileData[ index ], double, 1 + numNodes ); - } + profileData = alloc_profile_data((size_t) numNodes + 1); + /* the number of points is stored as profileData[0][0] */ profileData[0][0] = numNodes; for( index = 1; index <= numNodes; index++ ) { - profileData[ 0 ][ index ] = x[ index ]; - profileData[ 1 ][ index ] = conc[ index ]; + profileData[ 0 ][ index ] = x[ index ]; + profileData[ 1 ][ index ] = conc[ index ]; } /* Now create a new lookup table */ - XCALLOC( tmpTable, DOPtable, 1 ); + XCALLOC(tmpTable, DOPtable, 1); if ( *ppTable == NULL ) { /* First Entry */ tmpTable->impId = 1; @@ -161,8 +200,46 @@ readSupremData(char *fileName, int fileType, int impType, DOPtable **ppTable) printf("%e %e\n", profileData[ 0 ][ index ], profileData[ 1 ][ index ]); } */ - return; -} +EXITPOINT: + if (xrc != 0) { + free_profile_data(profileData); + free(tmpTable); + } + return xrc; +} /* end of function readSupremData */ + + + +/* Allocate a profile data */ +static double **alloc_profile_data(size_t n) +{ + double **p; + XCALLOC(p, double *, 2); + XCALLOC(p[0], double, n); + XCALLOC(p[1], double, n); + return p; +} /* end of function alloc_profile_data */ + + + +/* Free a profile data */ +static void free_profile_data(double **p) +{ + /* Immediate exit if no allocation */ + if (p == (double **) NULL) { + return; + } + + free(p[0]); + free(p[1]); + free(p); +} /* end of function alloc_profile_data */ + + + + + + /* main program to debug readSupremData */ diff --git a/src/ciderlib/support/suprmitf.c b/src/ciderlib/support/suprmitf.c index 3baafc548..9b9d1afa2 100644 --- a/src/ciderlib/support/suprmitf.c +++ b/src/ciderlib/support/suprmitf.c @@ -8,25 +8,31 @@ Author: 1991 David A. Gates, U. C. Berkeley CAD Group * the data is read and stored in two arrays x and conc */ +#include +#include -#include "ngspice/ngspice.h" #include "ngspice/cidersupt.h" +#include "ngspice/cpextern.h" +#include "ngspice/ngspice.h" #define MAXMAT 10 #define MAXIMP 4 #define MAXLAYER 10 #define MAXGRID 500 -#define GFREAD( fp, ptr, type, num ) if (num && (fread( ptr,\ - sizeof(type), (unsigned)num, fp ) != (unsigned)num)) {\ - return;\ - } +#define GFREAD( fp, ptr, type, num )\ + if (num && (fread( ptr, sizeof(type), (size_t) num,\ + fp ) != (size_t) num)) {\ + xrc = -1;\ + goto EXITPOINT;\ + } #define DEBUG if (0) -void -SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod) +int SUPbinRead(const char *inFile, float *x, float *conc, int *impId, + int *numNod) { + int xrc = 0; int idata, recordMark; int ldata; int i, j; @@ -37,18 +43,20 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod) float xStart; float layerTh[10]; float con[500]; - FILE *fpSuprem; + FILE *fpSuprem = (FILE *) NULL; /* Clear Concentration Array */ for ( i=0; i < MAXGRID; i++ ) { conc[i] = 0.0; } - /* Open Input File */ - if ((fpSuprem = fopen( inFile, "r" )) == NULL) { - perror(inFile); - return; - } + /* Open Input File */ + if ((fpSuprem = fopen( inFile, "r" )) == NULL) { + (void) fprintf(cp_err, "Unable to read file \"%s\": %s.\n", + inFile, strerror(errno)); + xrc = -1; + goto EXITPOINT; + } /* * The first record contains the number of layers (I4), the number of @@ -199,17 +207,27 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod) DEBUG fprintf(stderr," %d\n", ldata ); GFREAD( fpSuprem, &recordMark, int, 1 ); - fclose( fpSuprem ); + if (fclose(fpSuprem) != 0) { + (void) fprintf(cp_err, "Unable to close file \"%s\": %s.\n", + inFile, strerror(errno)); + xrc = -1; + goto EXITPOINT; + } + fpSuprem = (FILE *) NULL; -/* shift silicon layer to beginning of array */ - for ( j=numLay; --j >= 0; ) - if (matTyp[ j ] == 1) - break; + /* shift silicon layer to beginning of array */ + for (j = numLay; --j >= 0; ) { + if (matTyp[j] == 1) { + break; + } + } + + if (j < 0) { + (void) fprintf(cp_err, "internal error in %s!\n", __FUNCTION__); + xrc = -1; + goto EXITPOINT; + } - if(j < 0) { - fprintf(stderr, "internal error in %s, bye !\n", __FUNCTION__); - controlled_exit(1); - } siIndex = j; @@ -223,15 +241,26 @@ SUPbinRead(char *inFile, float *x, float *conc, int *impId, int *numNod) /* Store number of valid nodes using pointer */ *numNod = numGrid; - return; -} -void -SUPascRead(char *inFile, float *x, float *conc, int *impId, int *numNod) +EXITPOINT: + if (fpSuprem != (FILE *) NULL) { + if (fclose(fpSuprem) != 0) { + (void) fprintf(cp_err, "Unable to close \"%s\" at exit: %s\n", + inFile, strerror(errno)); + xrc = -1; + } + } + + return xrc; +} /* end of function SUPbinRead */ + + + +int SUPascRead(const char *inFile, float *x, float *conc, int *impId, + int *numNod) { - int idata; + int xrc = 0; int i, j; - float rdata; char cdata[21]; int numLay, numImp, numGrid; int impTyp[4], matTyp[10], topNod[10], siIndex, offset; @@ -245,119 +274,196 @@ SUPascRead(char *inFile, float *x, float *conc, int *impId, int *numNod) conc[i] = 0.0; } - /* Open Input File */ - if ((fpSuprem = fopen( inFile, "r" )) == NULL) { - perror(inFile); - return; - } + /* Open Input File */ + if ((fpSuprem = fopen( inFile, "r" )) == NULL) { + (void) fprintf(cp_err, "Unable to open file \"%s\": %s.\n", + inFile, strerror(errno)); + xrc = -1; + goto EXITPOINT; + } /* * The first line contains the number of layers (I4), the number of * impurities (I4), and the number of nodes (I4) present in the structure. */ - fscanf( fpSuprem, "%d %d %d\n", &numLay, &numImp, &numGrid ); + if (fscanf( fpSuprem, "%d %d %d\n", &numLay, &numImp, &numGrid) != 3) { + (void) fprintf(cp_err, "Unable to read file first line of \"%s\"\n", + inFile); + xrc = -1; + goto EXITPOINT; + } + DEBUG fprintf( stderr, "set 1: %d %d %d\n", numLay, numImp, numGrid); -/* - * The second set of lines contains, for each layer, the material name (A20), - * the material type (I4), the layer thickness (R4), and the pointer to - * the top node of the layer (I4), and an unknown int and unknown float. - * The material type code: - * 1 - Si - * 2 - SiO2 - * 3 - Poly - * 4 - Si3N4 - * 5 - Alum - */ - for ( i=0; i < numLay; i++ ) { - fscanf( fpSuprem, "%s\n %d %e %d %d %e\n", - cdata, &matTyp[i], &layerTh[i], &topNod[i], &idata, &rdata ); - DEBUG fprintf(stderr,"set 2: %s: %d %f %d\n", - cdata, matTyp[i], layerTh[i], topNod[i] ); - } + /* + * The second set of lines contains, for each layer, the material name + * (A20), the material type (I4), the layer thickness (R4), and the + * pointer to the top node of the layer (I4), and an unknown int and + * unknown float. + * + * The material type code: + * 1 - Si + * 2 - SiO2 + * 3 - Poly + * 4 - Si3N4 + * 5 - Alum + */ + for (i = 0; i < numLay; ++i) { + int idata; + float rdata; + if (fscanf(fpSuprem, "%s\n %d %e %d %d %e\n", + cdata, &matTyp[i], &layerTh[i], &topNod[i], + &idata, &rdata) != 6) { + (void) fprintf(cp_err, "Unable to read layer %d " + "from file \"%s\".\n", + i + 1, inFile); + xrc = -1; + goto EXITPOINT; + } -/* - * The third set of lines contains, for each impurity, the name of the - * impurity (A20) and the type of impurity (I4). - */ - for ( i=0; i < numImp; i++ ) { - fscanf( fpSuprem, "%s\n %d\n", cdata, &impTyp[i] ); - DEBUG fprintf(stderr,"set 3: %s: %d\n", cdata, impTyp[i] ); - } + DEBUG fprintf(stderr,"set 2: %s: %d %f %d\n", + cdata, matTyp[i], layerTh[i], topNod[i]); + } /* end of loop over layers */ -/* - * The fourth set of lines contains, for each layer by each impurity, the - * integrated dopant (R4), and the interior concentration of the - * polysilicon grains (R4). - */ - for ( j=0; j < numLay; j++ ) { - for ( i=0; i < numImp; i++ ) { - fscanf( fpSuprem, "%e", &rdata ); - fscanf( fpSuprem, "%e", &rdata ); + /* + * The third set of lines contains, for each impurity, the name of the + * impurity (A20) and the type of impurity (I4). + */ + for (i = 0; i < numImp; ++i) { + if (fscanf( fpSuprem, "%s\n %d\n", cdata, &impTyp[i]) != 2) { + (void) fprintf(cp_err, "Unable to read impurity %d " + "from file \"%s\".\n", + i + 1, inFile); + xrc = -1; + goto EXITPOINT; + } + DEBUG fprintf(stderr,"set 3: %s: %d\n", cdata, impTyp[i]); + } /* end of loop over impurities */ + + /* + * The fourth set of lines contains, for each layer by each impurity, + * the integrated dopant (R4), and the interior concentration of the + * polysilicon grains (R4). + */ + for (j = 0; j < numLay; ++j) { + for (i = 0; i < numImp; ++i) { + float rdata; + if (fscanf(fpSuprem, "%e%e", &rdata, &rdata) != 2) { + (void) fprintf(cp_err, "Unable to read integrated dopant " + "and interior concentration of layer %d and " + "impurity %d from file \"%s\".\n", + j + 1, i + 1, inFile); + xrc = -1; + goto EXITPOINT; + } + } } - } - DEBUG fprintf(stderr,"set 4:\n" ); + DEBUG fprintf(stderr,"set 4:\n" ); -/* - * The fifth set of lines contains, for each node in the structure, - * the distance to the next deepest node (R4), the distance from the - * surface (R4), and, for each impurity type, the impurity's - * chemical concentration (R4) and the impurity's active concentration (R4). - */ - for ( i=1; i <= numGrid; i++ ) { - fscanf( fpSuprem, "%e %e", &rdata, &x[i] ); + /* + * The fifth set of lines contains, for each node in the structure, + * the distance to the next deepest node (R4), the distance from the + * surface (R4), and, for each impurity type, the impurity's + * chemical concentration (R4) and the impurity's active concentration (R4). + */ + for (i = 1; i <= numGrid; ++i) { + float rdata; + if (fscanf(fpSuprem, "%e %e", &rdata, &x[i]) != 2) { + (void) fprintf(cp_err, "Unable to read grid %d " + "from file \"%s\".\n", + i + 1, inFile); + xrc = -1; + goto EXITPOINT; + } - for ( j=0; j < numImp; j++ ) { -/* chemical concentration - not required */ - fscanf( fpSuprem, "%e", &con[i] ); - -/* store active concentration */ - fscanf( fpSuprem, "%e", &con[i] ); + for (j = 0; j < numImp; j++) { + float junk; + /* chemical concentration - not required */ + if (fscanf(fpSuprem, "%e", &junk) != 1) { + (void) fprintf(cp_err, "Unable to chemical concentration " + "%d of layer %d " + "from file \"%s\".\n", + j + 1, i + 1, inFile); + xrc = -1; + goto EXITPOINT; + } -/* orient sign properly */ - if (impTyp[j] == *impId) { -/*...Boron...*/ - if (impTyp[j] == 1) { - conc[i] = - con[i]; - } else { -/*...All Other Impurities: P, As, Sb ...*/ - conc[i] = con[i]; - } - } + /* store active concentration */ + if (fscanf(fpSuprem, "%e", &con[i]) != 1) { + (void) fprintf(cp_err, "Unable to active concentration " + "%d of layer %d " + "from file \"%s\".\n", + j + 1, i + 1, inFile); + xrc = -1; + goto EXITPOINT; + } + + /* orient sign properly */ + if (impTyp[j] == *impId) { + /*...Boron...*/ + if (impTyp[j] == 1) { + conc[i] = - con[i]; + } + else { + /*...All Other Impurities: P, As, Sb ...*/ + conc[i] = con[i]; + } + } + } + } /* end of loop over num grid */ + DEBUG fprintf( stderr, "set 5: %e %e\n", x[1], conc[1] ); + + /* + * The last line in the file contains some random stuff that might be + * useful to some people, the temperature in degrees Kelvin of the last + * diffusion step (R4), the phosphorus implant dose (R4), the arsenic + * implant flag (L4). However, we can just ignore that stuff. + */ + if (fclose(fpSuprem) != 0) { + (void) fprintf(cp_err, "Unable to close file \"%s\": %s.\n", + inFile, strerror(errno)); + xrc = -1; + goto EXITPOINT; } - } - DEBUG fprintf( stderr, "set 5: %e %e\n", x[1], conc[1] ); + fpSuprem = (FILE *) NULL; -/* - * The last line in the file contains some random stuff that might be - * useful to some people, the temperature in degrees Kelvin of the last - * diffusion step (R4), the phosphorus implant dose (R4), the arsenic - * implant flag (L4). However, we can just ignore that stuff. - */ - fclose( fpSuprem ); + /* shift silicon layer to beginning of array */ + for (j = numLay; --j >= 0; ) { + if (matTyp[j] == 1) { + break; + } + } + + if (j < 0) { + (void) fprintf(cp_err, "internal error in %s!\n", __FUNCTION__); + xrc = -1; + goto EXITPOINT; + } + + siIndex = j; + + offset = topNod[siIndex] - 1; + numGrid -= offset; + xStart = x[1 + offset]; + for (i = 1; i <= numGrid; i++) { + x[i] = x[i + offset] - xStart; + conc[i] = conc[i + offset]; + } + + /* Store number of valid nodes using pointer */ + *numNod = numGrid; + +EXITPOINT: + if (fpSuprem != (FILE *) NULL) { + if (fclose(fpSuprem) != 0) { + (void) fprintf(cp_err, "Unable to close \"%s\" at exit: %s\n", + inFile, strerror(errno)); + xrc = -1; + } + } + + return xrc; +} /* end of function SUPascRead */ -/* shift silicon layer to beginning of array */ - for ( j=numLay; --j >= 0; ) - if (matTyp[ j ] == 1) - break; - if(j < 0) { - fprintf(stderr, "internal error in %s, bye !\n", __FUNCTION__); - controlled_exit(1); - } - - siIndex = j; - - offset = topNod[ siIndex ] - 1; - numGrid -= offset; - xStart = x[1 + offset]; - for ( i=1; i <= numGrid; i++ ) { - x[i] = x[i + offset] - xStart; - conc[i] = conc[i + offset]; - } - -/* Store number of valid nodes using pointer */ - *numNod = numGrid; - return; -} diff --git a/src/ciderlib/twod/twodext.h b/src/ciderlib/twod/twodext.h index 6a8330536..c2adf9ee9 100644 --- a/src/ciderlib/twod/twodext.h +++ b/src/ciderlib/twod/twodext.h @@ -153,7 +153,7 @@ extern BOOLEAN TWOdeltaConverged(TWOdevice *); extern BOOLEAN TWOdeviceConverged(TWOdevice *); extern void TWOresetJacobian(TWOdevice *); extern void TWOstoreNeutralGuess(TWOdevice *); -extern void TWOequilSolve(TWOdevice *); +extern int TWOequilSolve(TWOdevice *); extern void TWObiasSolve(TWOdevice *, int, BOOLEAN, TWOtranInfo *); extern void TWOstoreEquilibGuess(TWOdevice *); extern void TWOstoreInitialGuess(TWOdevice *); diff --git a/src/ciderlib/twod/twodopng.c b/src/ciderlib/twod/twodopng.c index 779831123..77d0d4d05 100644 --- a/src/ciderlib/twod/twodopng.c +++ b/src/ciderlib/twod/twodopng.c @@ -98,6 +98,7 @@ TWOdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x, } else { value = pProfile->PEAK_CONC * exp( -argP ); } + break; case EXP: argP = ABS(argP); if ( argP > 80.0 ) { @@ -143,6 +144,7 @@ TWOdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x, } else { value *= exp( -argL ); } + break; case EXP: argL = ABS(argL); if ( argL > 80.0 ) { diff --git a/src/ciderlib/twod/twosolve.c b/src/ciderlib/twod/twosolve.c index 1ea8c7730..7be06a1fe 100644 --- a/src/ciderlib/twod/twosolve.c +++ b/src/ciderlib/twod/twosolve.c @@ -4,21 +4,20 @@ Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group Author: 1991 David A. Gates, U. C. Berkeley CAD Group **********/ +#include "../../maths/misc/norm.h" +#include "ngspice/bool.h" +#include "ngspice/cidersupt.h" +#include "ngspice/cpextern.h" +#include "ngspice/ifsim.h" +#include "ngspice/macros.h" #include "ngspice/ngspice.h" -#include "ngspice/numglobs.h" #include "ngspice/numenum.h" +#include "ngspice/numglobs.h" +#include "ngspice/spmatrix.h" #include "ngspice/twodev.h" #include "ngspice/twomesh.h" -#include "ngspice/spmatrix.h" -#include "ngspice/bool.h" -#include "ngspice/macros.h" #include "twoddefs.h" #include "twodext.h" -#include "ngspice/cidersupt.h" -#include "../../maths/misc/norm.h" - - -#include "ngspice/ifsim.h" extern IFfrontEnd *SPfrontEnd; @@ -96,19 +95,24 @@ TWOdcSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN newSolver, error = spFactor(pDevice->matrix); factorTime += SPfrontEnd->IFseconds() - startTime; if (newSolver) { - if (pDevice->iterationNumber == 1) { - orderTime = factorTime; - } else if (pDevice->iterationNumber == 2) { - orderTime -= factorTime - orderTime; - factorTime -= orderTime; - if (pDevice->poissonOnly) { - pDevice->pStats->orderTime[STAT_SETUP] += orderTime; - } else { - pDevice->pStats->orderTime[STAT_DC] += orderTime; - } - newSolver = FALSE; - } - } + if (pDevice->iterationNumber == 1) { + orderTime = factorTime; + } + else if (pDevice->iterationNumber == 2) { + orderTime -= factorTime - orderTime; + factorTime -= orderTime; + if (pDevice->poissonOnly) { + pDevice->pStats->orderTime[STAT_SETUP] += orderTime; + } + else { + pDevice->pStats->orderTime[STAT_DC] += orderTime; + } + /* After first two iterations, no special handling for a + * new solver */ + newSolver = FALSE; + } /* end of case of iteratin 2 */ + } /* end of special processing for a new solver */ + if (foundError(error)) { if (error == spSINGULAR) { int badRow, badCol; @@ -430,58 +434,69 @@ TWOstoreNeutralGuess(TWOdevice *pDevice) /* computing the equilibrium solution; solution of Poisson's eqn */ /* the solution is used as an initial starting point for bias conditions */ - -void -TWOequilSolve(TWOdevice *pDevice) +int TWOequilSolve(TWOdevice *pDevice) { - BOOLEAN newSolver = FALSE; - int error; - int nIndex, eIndex; - TWOelem *pElem; - TWOnode *pNode; - double startTime, setupTime, miscTime; + BOOLEAN newSolver = FALSE; + int error; + int nIndex, eIndex; + TWOelem *pElem; + TWOnode *pNode; + double startTime, setupTime, miscTime; - setupTime = miscTime = 0.0; + setupTime = miscTime = 0.0; - /* SETUP */ - startTime = SPfrontEnd->IFseconds(); - switch (pDevice->solverType) { - case SLV_SMSIG: - case SLV_BIAS: - /* free up memory allocated for the bias solution */ - FREE(pDevice->dcSolution); - FREE(pDevice->dcDeltaSolution); - FREE(pDevice->copiedSolution); - FREE(pDevice->rhs); - FREE(pDevice->rhsImag); - spDestroy(pDevice->matrix); - case SLV_NONE: - pDevice->poissonOnly = TRUE; - pDevice->numEqns = pDevice->dimEquil - 1; - XCALLOC(pDevice->dcSolution, double, pDevice->dimEquil); - XCALLOC(pDevice->dcDeltaSolution, double, pDevice->dimEquil); - XCALLOC(pDevice->copiedSolution, double, pDevice->dimEquil); - XCALLOC(pDevice->rhs, double, pDevice->dimEquil); - pDevice->matrix = spCreate(pDevice->numEqns, 0, &error); - if (error == spNO_MEMORY) { - printf("TWOequilSolve: Out of Memory\n"); - exit(-1); - } - newSolver = TRUE; - spSetReal(pDevice->matrix); - TWOQjacBuild(pDevice); - pDevice->numOrigEquil = spElementCount(pDevice->matrix); - pDevice->numFillEquil = 0; - case SLV_EQUIL: - pDevice->solverType = SLV_EQUIL; - break; - default: - fprintf(stderr, "Panic: Unknown solver type in equil solution.\n"); - exit(-1); - break; - } - TWOstoreNeutralGuess(pDevice); - setupTime += SPfrontEnd->IFseconds() - startTime; + /* SETUP */ + startTime = SPfrontEnd->IFseconds(); + + /* Set up pDevice to compute the equilibrium solution. If the solver + * is for bias, the arrays must be freed and allocated to the correct + * sizes for an equilibrium solution; if it is a new solver, they are + * only allocated; and if already an equilibrium solve, nothing + * needs to be done */ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (pDevice->solverType) { + case SLV_SMSIG: + case SLV_BIAS: + /* Free memory allocated for the bias solution */ + FREE(pDevice->dcSolution); + FREE(pDevice->dcDeltaSolution); + FREE(pDevice->copiedSolution); + FREE(pDevice->rhs); + FREE(pDevice->rhsImag); + spDestroy(pDevice->matrix); + /* FALLTHROUGH */ + case SLV_NONE: { + /* Allocate memory needed for an equilibrium solution */ + const int n_dim = pDevice->dimEquil; + const int n_eqn = n_dim - 1; + pDevice->poissonOnly = TRUE; + pDevice->numEqns = n_eqn; + XCALLOC(pDevice->dcSolution, double, n_dim); + XCALLOC(pDevice->dcDeltaSolution, double, n_dim); + XCALLOC(pDevice->copiedSolution, double, n_dim); + XCALLOC(pDevice->rhs, double, n_dim); + pDevice->matrix = spCreate(n_eqn, 0, &error); + if (error == spNO_MEMORY) { + (void) fprintf(cp_err, "TWOequilSolve: Out of Memory\n"); + return E_NOMEM; + } + newSolver = TRUE; + spSetReal(pDevice->matrix); /* set to a real matrix */ + TWOQjacBuild(pDevice); + pDevice->numOrigEquil = spElementCount(pDevice->matrix); + pDevice->numFillEquil = 0; + pDevice->solverType = SLV_EQUIL; + break; + } + case SLV_EQUIL: /* Nothing to do if already equilibrium solver */ + break; + default: /* Invalid data */ + fprintf(stderr, "Panic: Unknown solver type in equil solution.\n"); + return E_PANIC; + } /* end of switch over solve type */ + TWOstoreNeutralGuess(pDevice); + setupTime += SPfrontEnd->IFseconds() - startTime; /* SOLVE */ TWOdcSolve(pDevice, MaxIterations, newSolver, FALSE, NULL); @@ -510,6 +525,8 @@ TWOequilSolve(TWOdevice *pDevice) miscTime += SPfrontEnd->IFseconds() - startTime; pDevice->pStats->setupTime[STAT_SETUP] += setupTime; pDevice->pStats->miscTime[STAT_SETUP] += miscTime; + + return 0; } /* compute the solution under an applied bias */ @@ -530,15 +547,20 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis, /* SETUP */ startTime = SPfrontEnd->IFseconds(); - switch (pDevice->solverType) { - case SLV_EQUIL: - /* free up the vectors allocated in the equilibrium solution */ - FREE(pDevice->dcSolution); - FREE(pDevice->dcDeltaSolution); - FREE(pDevice->copiedSolution); - FREE(pDevice->rhs); - spDestroy(pDevice->matrix); + /* Set up for solving for bias */ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (pDevice->solverType) { + case SLV_EQUIL: + /* free up the vectors allocated in the equilibrium solution */ + FREE(pDevice->dcSolution); + FREE(pDevice->dcDeltaSolution); + FREE(pDevice->copiedSolution); + FREE(pDevice->rhs); + spDestroy(pDevice->matrix); + /* FALLTHROUGH */ case SLV_NONE: + /* Set up for bias */ pDevice->poissonOnly = FALSE; pDevice->numEqns = pDevice->dimBias - 1; XCALLOC(pDevice->dcSolution, double, pDevice->dimBias); @@ -562,11 +584,13 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis, pDevice->numOrigBias = spElementCount(pDevice->matrix); pDevice->numFillBias = 0; TWOstoreInitialGuess(pDevice); + /* FALLTHROUGH */ case SLV_SMSIG: spSetReal(pDevice->matrix); - case SLV_BIAS: pDevice->solverType = SLV_BIAS; break; + case SLV_BIAS: + break; default: fprintf(stderr, "Panic: Unknown solver type in bias solution.\n"); exit(-1); diff --git a/src/frontend/arg.c b/src/frontend/arg.c index 6a09b1c86..dcd07e5b4 100644 --- a/src/frontend/arg.c +++ b/src/frontend/arg.c @@ -78,10 +78,12 @@ arg_plot(const wordlist *wl, const struct comm *command) void -arg_load(wordlist *wl, const struct comm *command) +arg_load(const wordlist *wl_in, const struct comm *command) { /* just call com_load */ + wordlist * const wl = wl_copy(wl_in); command->co_func(wl); + wl_free(wl); } @@ -91,15 +93,13 @@ void arg_let(const wordlist *wl, const struct comm *command) } -void -arg_set(const wordlist *wl, const struct comm *command) +void arg_set(const wordlist *wl, const struct comm *command) { common("which variable", wl, command); } -void -arg_display(const wordlist *wl, const struct comm *command) +void arg_display(const wordlist *wl, const struct comm *command) { NG_IGNORE(wl); NG_IGNORE(command); diff --git a/src/frontend/arg.h b/src/frontend/arg.h index de9ec6f09..7c049b45d 100644 --- a/src/frontend/arg.h +++ b/src/frontend/arg.h @@ -10,7 +10,7 @@ char *prompt(FILE *fp); wordlist *process(wordlist *wlist); void arg_print(const wordlist *wl, const struct comm *command); void arg_plot(const wordlist *wl, const struct comm *command); -void arg_load(wordlist *wl, const struct comm *command); +void arg_load(const wordlist *wl, const struct comm *command); void arg_let(const wordlist *wl, const struct comm *command); void arg_set(const wordlist *wl, const struct comm *command); void arg_display(const wordlist *wl, const struct comm *command); diff --git a/src/frontend/com_alias.h b/src/frontend/com_alias.h index b7b06f697..45747769c 100644 --- a/src/frontend/com_alias.h +++ b/src/frontend/com_alias.h @@ -6,6 +6,8 @@ #ifndef ngspice_COM_ALIAS_H #define ngspice_COM_ALIAS_H +#include "ngspice/wordlist.h" + void com_alias(wordlist *wl); void com_unalias(wordlist *wl); diff --git a/src/frontend/com_hardcopy.c b/src/frontend/com_hardcopy.c index 2a7cba1a8..a9c7e61fb 100644 --- a/src/frontend/com_hardcopy.c +++ b/src/frontend/com_hardcopy.c @@ -188,9 +188,15 @@ void com_hardcopy(wordlist *wl) if (!cp_getvar("lprplot5", CP_STRING, format, sizeof(format))) strcpy(format, SYSTEM_PLOT5LPR); (void) sprintf(buf, format, device, fname); - fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); - (void) system(buf); - printed = 1; + if (system(buf) == -1) { + fprintf(cp_out, "Printing %s on the %s printer failed.\n", + fname, device); + } + else { + fprintf(cp_out, "Printing %s on the %s printer OK.\n", + fname, device); + printed = 1; + } } #endif #ifdef SYSTEM_PSLPR @@ -199,9 +205,15 @@ void com_hardcopy(wordlist *wl) if (!cp_getvar("lprps", CP_STRING, format, sizeof(format))) strcpy(format, SYSTEM_PSLPR); (void) sprintf(buf, format, device, fname); - fprintf(cp_out, "Printing %s on the %s printer.\n", fname, device); - (void) system(buf); - printed = 1; + if (system(buf) == -1) { + fprintf(cp_out, "Printing %s on the %s printer failed.\n", + fname, device); + } + else { + fprintf(cp_out, "Printing %s on the %s printer OK.\n", + fname, device); + printed = 1; + } } #endif } diff --git a/src/frontend/com_let.c b/src/frontend/com_let.c index af91f8339..e8a2f261f 100644 --- a/src/frontend/com_let.c +++ b/src/frontend/com_let.c @@ -192,11 +192,11 @@ void com_let(wordlist *wl) vec_dst->v_compdata = TMALLOC(ngcomplex_t, n_elem_alloc); } - /* Make the destination vector the right data type. A few + /* Make the destination vector the right data type. A few * extra () added to keep some compilers from warning. */ - vec_dst->v_flags = - (vec_dst->v_flags & ~(VF_REAL | VF_COMPLEX)) | - (vec_src->v_flags & (VF_REAL | VF_COMPLEX)); + vec_dst->v_flags = (short int) ( + ((int) vec_dst->v_flags & ~(VF_REAL | VF_COMPLEX)) | + ((int) vec_src->v_flags & (VF_REAL | VF_COMPLEX))); vec_dst->v_alloc_length = vec_src->v_alloc_length; vec_dst->v_length = vec_src->v_length; copy_vector_data(vec_dst, vec_src); @@ -514,7 +514,7 @@ static void copy_vector_data(struct dvec *vec_dst, const size_t length = (size_t) vec_src->v_length; int n_dim = vec_dst->v_numdims = vec_src->v_numdims; (void) memcpy(vec_dst->v_dims, vec_src->v_dims, - n_dim * sizeof(int)); + (size_t) n_dim * sizeof(int)); if (isreal(vec_src)) { (void) memcpy(vec_dst->v_realdata, vec_src->v_realdata, length * sizeof(double)); @@ -686,13 +686,13 @@ static void copy_vector_data_with_stride(struct dvec *vec_dst, if (isreal(vec_src)) { /* Both real */ n_byte_elem = (int) sizeof(double); - n_byte_topdim = (int) n_elem_topdim * sizeof(double); + n_byte_topdim = n_elem_topdim * (int) sizeof(double); p_vec_data_dst = vec_dst->v_realdata; p_vec_data_src = vec_src->v_realdata; } else { n_byte_elem = (int) sizeof(ngcomplex_t); - n_byte_topdim = (int) n_elem_topdim * sizeof(ngcomplex_t); + n_byte_topdim = n_elem_topdim * (int) sizeof(ngcomplex_t); p_vec_data_dst = vec_dst->v_compdata; p_vec_data_src = vec_src->v_compdata; } @@ -733,15 +733,15 @@ static void copy_vector_data_with_stride(struct dvec *vec_dst, { const int n_cpy = n_dim - 2; /* index where copying done */ const void *p_vec_data_src_end = (char *) p_vec_data_src + - (size_t) vec_src->v_length * - n_byte_elem; /* end of copying */ + (size_t) (vec_src->v_length * n_byte_elem); + /* end of copying */ for ( ; ; ) { /* Copy the data currently being located by the cumulative * offset and the source location */ (void) memcpy( (char *) p_vec_data_dst + p_offset_level_cum[n_cpy], p_vec_data_src, - n_byte_topdim); + (size_t) n_byte_topdim); /* Move to the next source data and exit the loop if * the end is reached. diff --git a/src/frontend/com_shell.c b/src/frontend/com_shell.c index fedf1cb19..96e60417f 100644 --- a/src/frontend/com_shell.c +++ b/src/frontend/com_shell.c @@ -1,6 +1,7 @@ /************* * com_shell.c ************/ +#include #include "ngspice/ngspice.h" #include "ngspice/wordlist.h" @@ -20,7 +21,7 @@ void com_shell(wordlist *wl) { - char *com, *shell = NULL; + char *shell = NULL; shell = getenv("SHELL"); if (shell == NULL) { @@ -39,8 +40,9 @@ com_shell(wordlist *wl) execl(shell, shell, 0); _exit(99); } else { - com = wl_flatten(wl); + char * const com = wl_flatten(wl); execl("/bin/sh", "sh", "-c", com, 0); + txfree(com); } } else { /* XXX Better have all these signals */ @@ -58,12 +60,20 @@ com_shell(wordlist *wl) #else /* Easier to forget about changing the io descriptors. */ if (wl) { - com = wl_flatten(wl); - system(com); - tfree(com); - } else { - system(shell); + char * const com = wl_flatten(wl); + if (system(com) == -1) { + (void) fprintf(cp_err, "Unable to execute \"%s\".\n", com); + } + txfree(com); + } + else { + if (system(shell) == -1) { + (void) fprintf(cp_err, "Unable to execute \"%s\".\n", shell); + } } #endif -} +} /* end of function com_shell */ + + + diff --git a/src/frontend/com_sysinfo.c b/src/frontend/com_sysinfo.c index 13051c892..02a43a110 100644 --- a/src/frontend/com_sysinfo.c +++ b/src/frontend/com_sysinfo.c @@ -267,7 +267,14 @@ static void set_static_system_info(void) system_info.osName = TMALLOC(char, size + 1); rewind(file); - fread(system_info.osName, sizeof(char), size, file); + if (fread(system_info.osName, sizeof(char), size, file) != size) { + (void) fprintf(cp_err, "Unable to read \"/proc/version\".\n"); + fclose(file); + tfree(system_info.osName); + return; + } + + fclose(file); system_info.osName[size] = '\0'; @@ -289,7 +296,12 @@ static void set_static_system_info(void) /* get complete string */ inStr = TMALLOC(char, size+1); rewind(file); - fread(inStr, sizeof(char), size, file); + if (fread(inStr, sizeof(char), size, file) != size) { + (void) fprintf(cp_err, "Unable to read \"/proc/cpuinfo\".\n"); + fclose(file); + txfree(inStr); + return; + } inStr[size] = '\0'; { @@ -379,7 +391,7 @@ static void set_static_system_info(void) * } */ - tfree(inStr); + txfree(inStr); fclose(file); } /* end of case that file was opened OK */ diff --git a/src/frontend/diff.c b/src/frontend/diff.c index ed5f74d02..e11e6ece0 100644 --- a/src/frontend/diff.c +++ b/src/frontend/diff.c @@ -40,8 +40,7 @@ canonical_name(const char *name, DSTRINGPTR dbuf_p, size_t n = strlen(p_start) - 1; /* copy all but final ')' */ ds_case_t case_type = make_i_name_lower ? ds_case_lower : ds_case_as_is; - bool f_ok = ds_cat_mem_case(dbuf_p, p_start, (int) n, - case_type) == DS_E_OK; + bool f_ok = ds_cat_mem_case(dbuf_p, p_start, n, case_type) == DS_E_OK; f_ok &= ds_cat_mem(dbuf_p, sz_branch, sizeof sz_branch / sizeof *sz_branch - 1) == DS_E_OK; if (!f_ok) { diff --git a/src/frontend/dimens.c b/src/frontend/dimens.c index 4df084fff..07f2a9f1b 100644 --- a/src/frontend/dimens.c +++ b/src/frontend/dimens.c @@ -213,7 +213,7 @@ static int atodims_bracketed(const char *p, int *data, int *p_n_dim) int rc = get_bracketed_dim(p, data + n_dim); if (rc <= 0) { /* error or normal exit */ - *p_n_dim = n_dim; + *p_n_dim = (int) n_dim; return !!rc; } p += rc; /* step after the dimension that was processed */ @@ -283,10 +283,10 @@ static int atodims_csv(const char *p, int *data, int *p_n_dim) ++p; break; case ']': /* ] ended scan */ - *p_n_dim = n_dim; + *p_n_dim = (int) n_dim; return (int) (p - p0) + 1; case '\0': /* end of string ended scan */ - *p_n_dim = n_dim; + *p_n_dim = (int) n_dim; return 0; default: /* invalid char */ return -1; @@ -347,7 +347,7 @@ static int get_dim(const char *p, int *p_val) const char *p0 = p; for ( ; ; ++p) { const char c_cur = *p; - unsigned int digit_cur = c_cur - '0'; + unsigned int digit_cur = (unsigned int) (c_cur - '0'); unsigned int val_new; if (digit_cur > 9) { /* not a digit */ if ((*p_val = (int) val) < 0) { /* overflow */ diff --git a/src/frontend/display.c b/src/frontend/display.c index 797cd0103..9ad29be0a 100644 --- a/src/frontend/display.c +++ b/src/frontend/display.c @@ -246,10 +246,9 @@ DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta) } -void -DevDrawText(char *text, int x, int y, int angle) +void DevDrawText(const char *text, int x, int y, int angle) { - dispdev->DrawText (text, x, y, angle); + dispdev->DrawText(text, x, y, angle); } @@ -275,9 +274,9 @@ SetLinestyle(int linestyleid) void -SetColor(int colorid, GRAPH *graph) +SetColor(int colorid) { - dispdev->SetColor (colorid, graph); + dispdev->SetColor(colorid); } diff --git a/src/frontend/display.h b/src/frontend/display.h index df7944d21..355ff7737 100644 --- a/src/frontend/display.h +++ b/src/frontend/display.h @@ -19,11 +19,11 @@ void DevClose(void); void DevClear(void); void DevDrawLine(int x1, int y1, int x2, int y2, bool isgrid); void DevDrawArc(int x0, int y0, int radius, double theta, double delta_theta); -void DevDrawText(char *text, int x, int y, int angle); +void DevDrawText(const char *text, int x, int y, int angle); void DefineColor(int colorid, double red, double green, double blue); void DefineLinestyle(int linestyleid, int mask); void SetLinestyle(int linestyleid); -void SetColor(int colorid, GRAPH* graph); +void SetColor(int colorid); void DevUpdate(void); void DatatoScreen(GRAPH *graph, double x, double y, int *screenx, int *screeny); void Input(REQUEST *request, RESPONSE *response); diff --git a/src/frontend/get_avail_mem_size.c b/src/frontend/get_avail_mem_size.c index aadd4f4e3..af737427c 100644 --- a/src/frontend/get_avail_mem_size.c +++ b/src/frontend/get_avail_mem_size.c @@ -5,6 +5,7 @@ */ #include "ngspice/ngspice.h" +#include "resource.h" #if defined(_WIN32) #undef BOOLEAN @@ -29,7 +30,7 @@ /** * Returns the size of available memory (RAM) in bytes. */ -unsigned long long getAvailableMemorySize( ) +unsigned long long getAvailableMemorySize(void) { #if defined(HAVE__PROC_MEMINFO) /* Cygwin , Linux--------------------------------- */ diff --git a/src/frontend/get_phys_mem_size.c b/src/frontend/get_phys_mem_size.c index ef6c47b91..378f7115d 100644 --- a/src/frontend/get_phys_mem_size.c +++ b/src/frontend/get_phys_mem_size.c @@ -7,6 +7,7 @@ */ #include "ngspice/ngspice.h" +#include "resource.h" #if defined(_WIN32) #undef BOOLEAN @@ -29,7 +30,7 @@ /** * Returns the size of physical memory (RAM) in bytes. */ -unsigned long long getMemorySize() +unsigned long long getMemorySize(void) { #if defined(HAVE__PROC_MEMINFO) /* Cygwin , Linux--------------------------------- */ diff --git a/src/frontend/get_resident_set_size.c b/src/frontend/get_resident_set_size.c index 888b022e3..aeff60558 100644 --- a/src/frontend/get_resident_set_size.c +++ b/src/frontend/get_resident_set_size.c @@ -7,6 +7,7 @@ */ #include "ngspice/ngspice.h" +#include "resource.h" #if defined(_WIN32) #undef BOOLEAN @@ -39,7 +40,7 @@ * memory use) measured in bytes, or zero if the value cannot be * determined on this OS. */ -unsigned long long getPeakRSS() +unsigned long long getPeakRSS(void) { #if defined(HAVE__PROC_MEMINFO) /* Linux ---------------------------------------------------- */ @@ -100,7 +101,7 @@ unsigned long long getPeakRSS() * Returns the current resident set size (physical memory use) measured * in bytes, or zero if the value cannot be determined on this OS. */ -unsigned long long getCurrentRSS( ) +unsigned long long getCurrentRSS(void) { #if defined(_WIN32) /* Windows -------------------------------------------------- */ diff --git a/src/frontend/help/readhelp.c b/src/frontend/help/readhelp.c index 1828885b1..5cc819936 100644 --- a/src/frontend/help/readhelp.c +++ b/src/frontend/help/readhelp.c @@ -22,6 +22,7 @@ static toplink *getsubtoplink(char **ss); static topic *alltopics = NULL; static fplace *copy_fplace(fplace *place); +static void hlp_topic_free(topic *p_topic); static int @@ -37,28 +38,34 @@ sortcmp(const void *a, const void *b) static void sortlist(toplink **tlp) { - toplink **vec, *tl; + toplink *tl; size_t num = 0, i; - for (tl = *tlp; tl; tl = tl->next) + for (tl = *tlp; tl; tl = tl->next) { num++; - if (!num) + } + if (!num) { /* nothing to sort */ return; - vec = TMALLOC(toplink *, num); - for (tl = *tlp, i = 0; tl; tl = tl->next, i++) + } + + toplink ** const vec = TMALLOC(toplink *, num); + for (tl = *tlp, i = 0; tl; tl = tl->next, i++) { vec[i] = tl; + } (void) qsort(vec, num, sizeof (toplink *), sortcmp); *tlp = vec[0]; - for (i = 0; i < num - 1; i++) + for (i = 0; i < num - 1; i++) { vec[i]->next = vec[i + 1]; + } vec[i]->next = NULL; - tfree(vec); + txfree(vec); } topic * hlp_read(fplace *place) { + int xrc = 0; char buf[BSIZE_SP]; topic *top = TMALLOC(topic, 1); toplink *topiclink; @@ -68,22 +75,44 @@ hlp_read(fplace *place) char *s; bool mof = FALSE; - if (!place) - return NULL; + if (!place) { + xrc = -1; + goto EXITPOINT; + } top->place = copy_fplace(place); /* get the title */ - if (!place->fp) + if (!place->fp) { place->fp = hlp_fopen(place->filename); - if (!place->fp) - return (NULL); + } + if (!place->fp) { + xrc = -1; + goto EXITPOINT; + } fseek(place->fp, place->fpos, SEEK_SET); - (void) fgets(buf, BSIZE_SP, place->fp); /* skip subject */ - (void) fgets(buf, BSIZE_SP, place->fp); - for (s = buf; *s && (*s != '\n'); s++) + + /* skip subject */ + if (fgets(buf, BSIZE_SP, place->fp) == (char *) NULL) { + fprintf(stderr, "missing subject\n"); + xrc = -1; + goto EXITPOINT; + } + if (fgets(buf, BSIZE_SP, place->fp) == (char *) NULL) { + fprintf(stderr, "missing title\n"); + xrc = -1; + goto EXITPOINT; + } + + for (s = buf; *s && (*s != '\n'); s++) { ; + } *s = '\0'; + if ((int) (s - buf) < 7) { + fprintf(stderr, "invalid title\n"); + xrc = -1; + goto EXITPOINT; + } top->title = copy(&buf[7]); /* don't copy "TITLE: " */ /* get the text */ @@ -93,8 +122,7 @@ hlp_read(fplace *place) break; if ((*buf == '\0') || /* SJB - bug fix */ !strncmp("SEEALSO: ", buf, 9) || - !strncmp("SUBTOPIC: ", buf, 10)) - { + !strncmp("SUBTOPIC: ", buf, 10)) { /* no text */ top->text = NULL; goto endtext; @@ -163,8 +191,15 @@ endtext: top->readlink = alltopics; alltopics = top; - return (top); -} +EXITPOINT: + if (xrc != 0) { /* free resources if error */ + hlp_topic_free(top); + top = (topic *) NULL; + } + + return top; +} /* end of function hlp_read */ + /* *ss is of the form filename:subject */ @@ -310,11 +345,18 @@ getsubject(fplace *place) return(NULL); fseek(place->fp, place->fpos, SEEK_SET); - (void) fgets(buf, BSIZE_SP, place->fp); + if (fgets(buf, BSIZE_SP, place->fp) == (char *) NULL) { + (void) fprintf(stderr, "Missing subject"); + return (char *) NULL; + } for (s = buf; *s && (*s != '\n'); s++) ; *s = '\0'; - return (copy(&buf[9])); /* don't copy "SUBJECT: " */ + if ((int) (s - buf) < 9) { + (void) fprintf(stderr, "Invalid subject"); + return (char *) NULL; + } + return copy(buf + 9); /* don't copy "SUBJECT: " */ } @@ -324,33 +366,41 @@ void tlfree(toplink *tl) toplink *nt = NULL; while (tl) { - tfree(tl->description); - tfree(tl->place->filename); - tfree(tl->place); + txfree(tl->description); + txfree(tl->place->filename); + txfree(tl->place); /* Don't free the button stuff... */ nt = tl->next; - tfree(tl); + txfree(tl); tl = nt; } } + void hlp_free(void) { - topic *top, *nt = NULL; + topic *top, *nt; for (top = alltopics; top; top = nt) { nt = top->readlink; - tfree(top->title); - tfree(top->place); - wl_free(top->text); - tlfree(top->subtopics); - tlfree(top->seealso); - tfree(top); + hlp_topic_free(top); } alltopics = NULL; -} +} /* end of function hlp_free */ + + +static void hlp_topic_free(topic *p_topic) +{ + txfree(p_topic->title); + txfree(p_topic->place); + wl_free(p_topic->text); + tlfree(p_topic->subtopics); + tlfree(p_topic->seealso); + txfree(p_topic); +} /* end of function hlp_topic_free */ + static fplace * diff --git a/src/frontend/hpgl.c b/src/frontend/hpgl.c index 77be5e6d1..e8040685d 100644 --- a/src/frontend/hpgl.c +++ b/src/frontend/hpgl.c @@ -250,7 +250,7 @@ int GL_Arc(int x0, int y0, int r, double theta, double delta_theta) } -int GL_Text(char *text, int x, int y, int angle) +int GL_Text(const char *text, int x, int y, int angle) { NG_IGNORE(angle); @@ -291,9 +291,8 @@ int GL_SetLinestyle(int linestyleid) } -int GL_SetColor(int colorid, GRAPH* graph) +int GL_SetColor(int colorid) { - NG_IGNORE(graph); fprintf(plotfile, "SP %d;", colorid); return 0; diff --git a/src/frontend/inp.c b/src/frontend/inp.c index 1726f56e7..6c9247343 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -1390,8 +1390,7 @@ com_edit(wordlist *wl) fprintf(cp_out, "run circuit? "); fflush(cp_out); - fgets(buf, BSIZE_SP, stdin); - if (buf[0] != 'n') { + if (fgets(buf, BSIZE_SP, stdin) == (char *) NULL || buf[0] != 'n') { fprintf(cp_out, "running circuit\n"); com_run(NULL); } diff --git a/src/frontend/misccoms.c b/src/frontend/misccoms.c index 40f35ede9..dcc42c7ab 100644 --- a/src/frontend/misccoms.c +++ b/src/frontend/misccoms.c @@ -3,23 +3,24 @@ Copyright 1990 Regents of the University of California. All rights reserved. Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group **********/ +#include "../misc/ivars.h" +#include "circuits.h" +#include "com_alias.h" +#include "define.h" +#include "display.h" +#include "ftehelp.h" +#include "misccoms.h" #include "ngspice/ngspice.h" #include "ngspice/cpdefs.h" #include "ngspice/ftedefs.h" #include "ngspice/dvec.h" #include "ngspice/iferrmsg.h" -#include "ftehelp.h" #include "ngspice/hlpdefs.h" -#include "misccoms.h" -#include "postcoms.h" -#include "circuits.h" -#include "variable.h" #include "plotting/graf.h" -#include "display.h" -#include "../misc/ivars.h" -#include "com_alias.h" -#include "define.h" +#include "plotting/plotit.h" +#include "postcoms.h" #include "runcoms2.h" +#include "variable.h" #ifdef HAVE_GNUREADLINE #include @@ -38,7 +39,6 @@ extern void rem_controls(void); extern IFsimulator SIMinfo; extern void spice_destroy_devices(void); /* FIXME need a better place */ -extern void pl_rempar(void); /* plotit.c */ static void byemesg(void); static int confirm_quit(void); @@ -136,7 +136,10 @@ com_bug(wordlist *wl) Bug_Addr); (void) sprintf(buf, SYSTEM_MAIL, ft_sim->simulator, ft_sim->version, Bug_Addr); - (void) system(buf); + if (system(buf) == -1) { + fprintf(cp_err, "Bug report could not be sent: \"%s\" failed.\n", + buf); + } fprintf(cp_out, "Bug report sent. Thank you.\n"); } diff --git a/src/frontend/numparam/mystring.c b/src/frontend/numparam/mystring.c index 8918de630..7793473b1 100644 --- a/src/frontend/numparam/mystring.c +++ b/src/frontend/numparam/mystring.c @@ -128,7 +128,7 @@ pscopy(DSTRINGPTR dstr_p, const char *t, const char *stop) } ds_clear(dstr_p); - if (ds_cat_mem(dstr_p, t, stop - t) != DS_E_OK) { + if (ds_cat_mem(dstr_p, t, (size_t) (stop - t)) != DS_E_OK) { controlled_exit(-1); } diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index b9cde18fe..4ea618bef 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -193,7 +193,7 @@ findsubname(dico_t *dico, DSTRINGPTR dstr_p) pscopy(&name, p, t); entry = entrynb(dico, ds_get_buf(&name)); if (entry && (entry->tp == NUPA_SUBCKT)) { - (void) ds_set_length(dstr_p, p_end - s); + (void) ds_set_length(dstr_p, (size_t) (p_end - s)); ds_free(&name); return; } @@ -247,7 +247,7 @@ transform(dico_t *dico, DSTRINGPTR dstr_p, bool incontrol) /* split off any "params" tail */ params = strstr(s, "params:"); if (params) { - ds_set_length(dstr_p, params - s); + ds_set_length(dstr_p, (size_t) (params - s)); } category = 'S'; } else if (prefix(".control", s)) { diff --git a/src/frontend/parser/glob.c b/src/frontend/parser/glob.c index ecdbd2075..49cbe78d7 100644 --- a/src/frontend/parser/glob.c +++ b/src/frontend/parser/glob.c @@ -146,7 +146,7 @@ static wordlist *bracexpand(const wordlist *w_exp) char ch_cur; for ( ; (ch_cur = *p_cur) != '\0'; p_cur++) { if (ch_cur == cp_ocurl) { - offset_ocurl = p_cur - wl_word; + offset_ocurl = (size_t) (p_cur - wl_word); break; } } @@ -246,7 +246,7 @@ static wordlist_l *brac1(size_t offset_ocurl1, const char *p_str) } } - const size_t n_char_append = s - p_start; + const size_t n_char_append = (size_t) (s - p_start); if (n_char_append > 0) { wordlist_l *wl; @@ -330,7 +330,7 @@ static wordlist_l *brac2(const char *string, } else if (ch_cur == cp_ocurl) { /* another brace level started */ if (nb++ == 0) { /* Inc count. If 1st '{', save offset */ - offset_ocurl1 = s - buf_cur; + offset_ocurl1 = (size_t) (s - buf_cur); } } else if ((ch_cur == cp_comma) && (nb == 0)) { @@ -366,7 +366,8 @@ static wordlist_l *brac2(const char *string, * wordlist being built */ { wordlist_l *nwl = brac1( - offset_ocurl1 == SIZE_MAX ? s - buf_cur : offset_ocurl1, + offset_ocurl1 == SIZE_MAX ? + (size_t) (s - buf_cur) : offset_ocurl1, buf_cur); wlist = wll_append(wlist, nwl); } @@ -379,7 +380,7 @@ static wordlist_l *brac2(const char *string, /* When the loop is exited, s is at a brace or comma, which * is also considered to be processed. Hence +2 not +1. */ - *p_n_char_processed = s - buf + 2; + *p_n_char_processed = (size_t) (s - buf + 2); return wlist; } @@ -434,7 +435,7 @@ static void tilde_expand_word(wordlist *wl_node) while ((c = *usr_end) != '\0' && c != DIR_TERM) { ++usr_end; } - const size_t n_char_usr = usr_end - usr_start; + const size_t n_char_usr = (size_t) (usr_end - usr_start); const size_t n_byte_usr = n_char_usr + 1; const char c_orig = c; /* save char to be overwritten by '\0' */ *usr_end = '\0'; @@ -447,7 +448,7 @@ static void tilde_expand_word(wordlist *wl_node) return; /* Strip the ~ and return the rest */ } merge_home_with_rest(wl_node, (size_t) n_char_home, sz_home, - n_char_usr + 1); + n_byte_usr); return; } diff --git a/src/frontend/parser/lexical.c b/src/frontend/parser/lexical.c index ee961a1b2..370ce1447 100644 --- a/src/frontend/parser/lexical.c +++ b/src/frontend/parser/lexical.c @@ -456,6 +456,8 @@ prompt(void) s = "-> "; while (*s) { + /* NOTE: The FALLTHROUGH comment is used to suppress a GCC warning + * when flag -Wimplicit-fallthrough is present */ switch (*s) { case '!': fprintf(cp_out, "%d", cp_event); @@ -463,6 +465,7 @@ prompt(void) case '\\': if (s[1]) (void) putc((*++s), cp_out); + /* FALLTHROUGH */ default: (void) putc((*s), cp_out); } diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 96a77fd5d..85b0c80c1 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -31,6 +31,8 @@ quote_gnuplot_string(FILE *stream, char *s) fputc('"', stream); for (; *s; s++) + /* NOTE: The FALLTHROUGH comment is used to suppress a GCC warning + * when flag -Wimplicit-fallthrough is present */ switch (*s) { case '\n': fputs("\\n", stream); @@ -38,6 +40,7 @@ quote_gnuplot_string(FILE *stream, char *s) case '"': case '\\': fputc('\\', stream); + /* FALLTHROUGH */ default: fputc(*s, stream); } diff --git a/src/frontend/plotting/graf.c b/src/frontend/plotting/graf.c index 6c427daeb..085c49eea 100644 --- a/src/frontend/plotting/graf.c +++ b/src/frontend/plotting/graf.c @@ -314,7 +314,7 @@ void gr_point(struct dvec *dv, return; } } - SetColor(dv->v_color, currentgraph); + SetColor(dv->v_color); switch (currentgraph->plottype) { double *tics; @@ -474,7 +474,7 @@ void drawlegend(GRAPH *graph, int plotno, struct dvec *dv) const int y = graph->absolute.height - graph->fontheight - ((plotno + 2) / 2) * (graph->fontheight); const int i = y + graph->fontheight / 2 + 1; - SetColor(dv->v_color, graph); + SetColor(dv->v_color); if (graph->plottype == PLOT_POINT) { char buf[16]; (void) sprintf(buf, "%c : ", dv->v_linestyle); @@ -484,7 +484,7 @@ void drawlegend(GRAPH *graph, int plotno, struct dvec *dv) SetLinestyle(dv->v_linestyle); DevDrawLine(x, i, x + graph->viewport.width / 20, i, FALSE); } - SetColor(1, graph); + SetColor(1); DevDrawText(dv->v_name, x + graph->viewport.width / 20 + graph->fontwidth, y, 0); } @@ -638,7 +638,7 @@ void gr_restoretext(GRAPH *graph) /* restore text */ for (k = graph->keyed; k; k = k->next) { - SetColor(k->colorindex, graph); + SetColor(k->colorindex); DevDrawText(k->text, k->x, k->y, 0); } } @@ -735,7 +735,7 @@ static int iplot(struct plot *pl, int id) for (yt = pl->pl_dvecs->v_type, v = pl->pl_dvecs->v_next; v; v = v->v_next) { - if ((v->v_flags & VF_PLOT) && (v->v_type != yt)) { + if ((v->v_flags & VF_PLOT) && ((int) v->v_type != yt)) { yt = SV_NOTYPE; break; } diff --git a/src/frontend/plotting/grid.c b/src/frontend/plotting/grid.c index 468b42350..433330bac 100644 --- a/src/frontend/plotting/grid.c +++ b/src/frontend/plotting/grid.c @@ -74,7 +74,7 @@ gr_fixgrid(GRAPH *graph, double xdelta, double ydelta, int xtype, int ytype) if (graph->grid.gridtype == GRID_NONE) graph->grid.gridtype = GRID_LIN; - SetColor(1, graph); + SetColor(1); SetLinestyle(1); if ((graph->data.xmin > graph->data.xmax) || @@ -132,7 +132,7 @@ void gr_redrawgrid(GRAPH *graph) { - SetColor(1, graph); + SetColor(1); SetLinestyle(1); /* draw labels */ if (graph->grid.xlabel) { @@ -182,9 +182,10 @@ gr_redrawgrid(GRAPH *graph) #ifdef HAS_WINGUI /* x axis centered to graphics on Windows */ /* utf-8: figure out the real length of the x label */ - wchar_t *wtext; - wtext = TMALLOC(wchar_t, 2 * strlen(graph->grid.xlabel) + 1); - int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.xlabel, -1, wtext, 2 * strlen(graph->grid.xlabel) + 1); + const int n_byte_wide = 2 * (int) strlen(graph->grid.xlabel) + 1; + wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.xlabel, -1, + wtext, n_byte_wide); if (wlen == 0) { fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError()); fprintf(stderr, "%s could not be converted\n", graph->grid.xlabel); @@ -206,6 +207,7 @@ gr_redrawgrid(GRAPH *graph) else unitshift = 0; /* reset for next plot window */ } + txfree(wtext); } #endif #endif // EXT_ASC @@ -221,26 +223,34 @@ gr_redrawgrid(GRAPH *graph) (graph->absolute.height * 3) / 4, 0); } else { - if (eq(dispdev->name, "postscript")) - DevDrawText(graph->grid.ylabel, + if (eq(dispdev->name, "postscript")) { + DevDrawText(graph->grid.ylabel, graph->fontwidth, - /*vertical text, midpoint in y is aligned midpoint of text string */ - (graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90); + /* vertical text, midpoint in y is aligned midpoint + * of text string */ + (graph->absolute.height - (int) strlen( + graph->grid.ylabel) * graph->fontwidth) / 2, + 90); + } #ifdef EXT_ASC else if (eq(dispdev->name, "Windows")) DevDrawText(graph->grid.ylabel, graph->fontwidth, - /*vertical text, midpoint in y is aligned midpoint of text string */ - (graph->absolute.height - strlen(graph->grid.ylabel) * graph->fontwidth) / 2, 90); + /* vertical text, midpoint in y is aligned midpoint + * of text string */ + (graph->absolute.height - (int) strlen( + graph->grid.ylabel) * graph->fontwidth) / 2, + 90); #else #ifdef HAS_WINGUI /* Windows and UTF-8: check for string length (in pixels), place vertical text centered in y with respect to grid */ else if (eq(dispdev->name, "Windows")) { /* utf-8: figure out the real length of the y label */ - wchar_t *wtext; - wtext = TMALLOC(wchar_t, 2 * strlen(graph->grid.ylabel) + 1); - int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.ylabel, -1, wtext, 2 * strlen(graph->grid.ylabel) + 1); + const int n_byte_wide = 2 * (int) strlen(graph->grid.ylabel) + 1; + wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + int wlen = MultiByteToWideChar(CP_UTF8, 0, graph->grid.ylabel, -1, + wtext, n_byte_wide); if (wlen == 0) { fprintf(stderr, "UTF-8 to wide char conversion failed with 0x%x\n", GetLastError()); fprintf(stderr, "%s could not be converted\n", graph->grid.ylabel); @@ -257,6 +267,7 @@ gr_redrawgrid(GRAPH *graph) /*vertical text, midpoint in y is aligned midpoint of text string */ (graph->absolute.height - (int)(1.2*sz.cx + tmw.tmOverhang)) / 2, 90); } + txfree(wtext); } #endif #endif @@ -1477,7 +1488,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d /* Let's be lazy and just draw everything -- we won't get called too * much and the circles get clipped anyway... */ - SetColor(18, graph); + SetColor(18); cliparc((double) (centx + xoffset + radoff - rad), (double) (centy + yoffset), rad, 2*angle, @@ -1491,7 +1502,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d M_PI - 2 * angle, centx, centy, maxrad, 0); /* Draw the upper and lower circles. */ - SetColor(19, graph); + SetColor(19); aclip = cliparc((double) (centx + xoffset + radoff), (double) (centy + yoffset + irad), irad, (double) (M_PI * 1.5 + 2 * iangle), @@ -1500,7 +1511,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d xlab = (int)(centx + xoffset + radoff + irad * cos(aclip)); ylab = (int)(centy + yoffset + irad * (1 + sin(aclip))); if ((ylab - gr_ycenter) > graph->fontheight) { - SetColor(1, graph); + SetColor(1); adddeglabel(graph, pdeg, xlab, ylab, gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter); /* @@ -1508,7 +1519,7 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d adddeglabel(graph, ndeg, xlab, ylab, gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter); */ - SetColor(19, graph); + SetColor(19); } } aclip = cliparc((double) (centx + xoffset + radoff), @@ -1519,14 +1530,14 @@ arcset(GRAPH *graph, double rad, double prevrad, double irad, double iprevrad, d if ((aclip >= 0 && aclip < 2*M_PI - M_PI/180) && (pdeg < 359)) { xlab = (int)(centx + xoffset + radoff + irad * cos(aclip)); ylab = (int)(centy + yoffset + irad * (sin(aclip) - 1)); - SetColor(1, graph); + SetColor(1); adddeglabel(graph, ndeg, xlab, ylab, gr_xcenter, gr_ycenter, gr_xcenter, gr_ycenter); - SetColor(19, graph); + SetColor(19); } /* Now toss the labels on... */ - SetColor(1, graph); + SetColor(1); x = centx + xoffset + (int)radoff - 2 * (int)rad - gi_fntwidth * (int) strlen(plab) - 2; diff --git a/src/frontend/plotting/plot5.c b/src/frontend/plotting/plot5.c index 155a089bb..b5723d5f4 100644 --- a/src/frontend/plotting/plot5.c +++ b/src/frontend/plotting/plot5.c @@ -170,7 +170,7 @@ int Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta) } -int Plt5_Text(char *text, int x, int y, int angle) +int Plt5_Text(const char *text, int x, int y, int angle) { int savedlstyle; NG_IGNORE(angle); @@ -211,10 +211,9 @@ int Plt5_SetLinestyle(int linestyleid) /* ARGSUSED */ -int Plt5_SetColor(int colorid, GRAPH *graph) +int Plt5_SetColor(int colorid) { NG_IGNORE(colorid); - NG_IGNORE(graph); /* do nothing */ return 0; diff --git a/src/frontend/plotting/plotit.c b/src/frontend/plotting/plotit.c index cd8166f1c..461c61c7e 100644 --- a/src/frontend/plotting/plotit.c +++ b/src/frontend/plotting/plotit.c @@ -27,33 +27,30 @@ static char *xlabel = NULL, *ylabel = NULL, *title = NULL; #include "ngspice/tclspice.h" #endif -/* remove the malloced parameters upon ngspice quit */ + +static struct dvec *vec_self(struct dvec *v); +static struct dvec *vec_scale(struct dvec *v); +static void find_axis_limits(double *lim, bool oneval, bool f_real, + struct dvec *vecs, + struct dvec *(*p_get_axis_dvec)(struct dvec *dvec), + double *lims); + + +/* Remove the malloced parameters upon ngspice quit. These are set to NULL + * to allow the function to be used at any time and safely called more than + * one time. */ void pl_rempar(void) { - txfree(xcompress); - txfree(xindices); - txfree(xlim); - txfree(ylim); - txfree(xdelta); - txfree(ydelta); - txfree(xlabel); - txfree(ylabel); + tfree(xcompress); + tfree(xindices); + tfree(xlim); + tfree(ylim); + tfree(xdelta); + tfree(ydelta); + tfree(xlabel); + tfree(ylabel); } -static struct dvec *vec_self(struct dvec *v); -static struct dvec *vec_scale(struct dvec *v); -static void find_axis_limits(double *lim, bool oneval, bool f_real, - struct dvec *vecs, - struct dvec *(*p_get_axis_dvec)(struct dvec *dvec), - double *lims); - - -static struct dvec *vec_self(struct dvec *v); -static struct dvec *vec_scale(struct dvec *v); -static void find_axis_limits(double *lim, bool oneval, bool f_real, - struct dvec *vecs, - struct dvec *(*p_get_axis_dvec)(struct dvec *dvec), - double *lims); /* This routine gets parameters from the command line, which are of @@ -294,7 +291,7 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname) struct pnode *pn, *names; struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL; char *xn; - int i, y_type, xt; + int i, xt; wordlist *wwl; char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL; double tstep, tstart, tstop, ttime; @@ -1080,7 +1077,7 @@ bool plotit(wordlist *wl, const char *hcopy, const char *devname) } } - y_type = d ? SV_NOTYPE : vecs->v_type; + const int y_type = (int) (d ? SV_NOTYPE : vecs->v_type); if (devname && eq(devname, "gnuplot")) { /* Interface to Gnuplot Plot Program */ diff --git a/src/frontend/plotting/plotit.h b/src/frontend/plotting/plotit.h index c57578eed..a5ca8a87a 100644 --- a/src/frontend/plotting/plotit.h +++ b/src/frontend/plotting/plotit.h @@ -2,5 +2,5 @@ #define ngspice_PLOTIT_H bool plotit(wordlist *wl, const char *hcopy, const char *devname); - +void pl_rempar(void); #endif diff --git a/src/frontend/plotting/x11.c b/src/frontend/plotting/x11.c index 8a88ce270..0352ec427 100644 --- a/src/frontend/plotting/x11.c +++ b/src/frontend/plotting/x11.c @@ -237,7 +237,11 @@ initcolors(GRAPH *graph) "yellow", "" }; - XColor visualcolor, exactcolor, bgcolor; + XColor visualcolor, exactcolor; + + /* Silence incorrect compiler warning about possibly not being init */ + XColor bgcolor = {0}; + char buf[BSIZE_SP], colorstring[BSIZE_SP]; int xmaxcolors = NUMCOLORS; /* note: can we get rid of this? */ @@ -273,9 +277,9 @@ initcolors(GRAPH *graph) t3 = copy(tmpstr); if (t1 && t2 && t3) { double c1, c2, c3; - c1 = strtol(t1, NULL, 10) / 255.; - c2 = strtol(t2, NULL, 10) / 255.; - c3 = strtol(t3, NULL, 10) / 255.; + c1 = (double) strtol(t1, NULL, 10) / 255.; + c2 = (double) strtol(t2, NULL, 10) / 255.; + c3 = (double) strtol(t3, NULL, 10) / 255.; c1 = fmax(0., fmin(c1, 1.)); c2 = fmax(0., fmin(c2, 1.)); c3 = fmax(0., fmin(c3, 1.)); @@ -310,7 +314,8 @@ initcolors(GRAPH *graph) /* select grid color according to background color. Empirical selection using the color depth of the background */ /* switch the grid and text color depending on background */ - int tcolor = (int)bgcolor.red + (int)(1.5 * bgcolor.green) + (int)bgcolor.blue; + int tcolor = (int) bgcolor.red + + (int) (1.5 * bgcolor.green) + (int) bgcolor.blue; if (tcolor > 92160) { graph->colorarray[1] = BlackPixel(display, DefaultScreen(display)); strncpy(DEVDEP(graph).txtcolor, "black", 15); @@ -351,7 +356,7 @@ handlekeypressed(Widget w, XtPointer client_data, XEvent *ev, Boolean *continue_ /* write it */ PushGraphContext(graph); text[nbytes] = '\0'; - SetColor(1, graph); + SetColor(1); DevDrawText(text, keyev->x, graph->absolute.height - keyev->y, 0); /* save it */ SaveText(graph, text, keyev->x, graph->absolute.height - keyev->y); @@ -652,7 +657,7 @@ X11_Close(void) int X11_DrawLine(int x1, int y1, int x2, int y2, bool isgrid) { - if (DEVDEP(currentgraph).isopen) + if (DEVDEP(currentgraph).isopen) { if (isgrid) { XDrawLine(display, DEVDEP(currentgraph).window, DEVDEP(currentgraph).gridgc, @@ -665,6 +670,7 @@ X11_DrawLine(int x1, int y1, int x2, int y2, bool isgrid) x1, currentgraph->absolute.height - y1, x2, currentgraph->absolute.height - y2); } + } return 0; } @@ -694,25 +700,26 @@ X11_Arc(int x0, int y0, int radius, double theta, double delta_theta) /* note: x and y are the LOWER left corner of text */ int -X11_Text(char *text, int x, int y, int angle) +X11_Text(const char *text, int x, int y, int angle) { /* We specify text position by lower left corner, so have to adjust for X11's font nonsense. */ - - int wlen = 0, wheight = 0; - #ifndef HAVE_LIBXFT - if (DEVDEP(currentgraph).isopen) - XDrawString(display, DEVDEP(currentgraph).window, - DEVDEP(currentgraph).gc, x, - currentgraph->absolute.height - - (y + DEVDEP(currentgraph).font->max_bounds.descent), - text, (int) strlen(text)); + if (DEVDEP(currentgraph).isopen) { + if (angle != 0) { + fprintf(stderr, " Xft: angles other than 0 are not supported\n"); + } + XDrawString(display, DEVDEP(currentgraph).window, + DEVDEP(currentgraph).gc, x, + currentgraph->absolute.height + - (y + DEVDEP(currentgraph).font->max_bounds.descent), + text, (int) strlen(text)); + } - /* note: unlike before, we do not save any text here */ + /* note: unlike before, we do not save any text here */ #else /* Draw text */ - if(angle == 0) { + if (angle == 0) { XftDrawStringUtf8( DEVDEP(currentgraph).draw, &DEVDEP(currentgraph).color, DEVDEP(currentgraph).font0, x, currentgraph->absolute.height - y, (FcChar8*)text, strlen(text)); @@ -838,7 +845,7 @@ X11_SetLinestyle(int linestyleid) int -X11_SetColor(int colorid, GRAPH *graph) +X11_SetColor(int colorid) { currentgraph->currentcolor = colorid; XSetForeground(display, DEVDEP(currentgraph).gc, diff --git a/src/frontend/postcoms.c b/src/frontend/postcoms.c index 0f628424c..4d1a7c1d4 100644 --- a/src/frontend/postcoms.c +++ b/src/frontend/postcoms.c @@ -803,13 +803,9 @@ com_cross(wordlist *wl) vec_remove(newvec); v = dvec_alloc(copy(newvec), - vecs - ? vecs->v_type - : SV_NOTYPE, - comp - ? (VF_COMPLEX | VF_PERMANENT) - : (VF_REAL | VF_PERMANENT), - i, NULL); + (int) (vecs ? vecs->v_type : SV_NOTYPE), + comp ? (VF_COMPLEX | VF_PERMANENT) : (VF_REAL | VF_PERMANENT), + i, NULL); /* Now copy the ind'ths elements into this one. */ for (n = vecs, i = 0; n; n = n->v_link2, i++) diff --git a/src/frontend/postsc.c b/src/frontend/postsc.c index aa6b55c98..c6032d829 100644 --- a/src/frontend/postsc.c +++ b/src/frontend/postsc.c @@ -108,7 +108,8 @@ static int maxcolor = 2; void PS_LinestyleColor(int linestyleid, int colorid); void PS_SelectColor(int colorid); void PS_Stroke(void); -size_t utf8_to_latin9(char *const output, const char *const input, const size_t length); +static size_t utf8_to_latin9(char * const output, const char *const input, + const size_t length); /* Set scale, color and size of the plot */ @@ -120,10 +121,15 @@ int PS_Init(void) if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) { scale = 1.0; - } else { - sscanf(psscale, "%lf", &scale); - if ((scale <= 0) || (scale > 10)) - scale = 1.0; + } + else if (sscanf(psscale, "%lf", &scale) != 1) { + (void) fprintf(cp_err, "Error getting scale value\n"); + scale = 1.0; + } + else if ((scale <= 0.0) || (scale > 10.0)) { + (void) fprintf(cp_err, "Scale value %lf is out of range\n", + scale); + scale = 1.0; } dispdev->numlinestyles = NUMELEMS(linestyle); /* plot color */ @@ -395,12 +401,18 @@ int PS_Arc(int x0, int y0, int r, double theta, double delta_theta) } -int PS_Text(char *text, int x, int y, int angle) +int PS_Text(const char *text_in, int x, int y, int angle) { int savedlstyle, savedcolor; - -#ifndef EXT_ASC - utf8_to_latin9(text, text, strlen(text)); + char *text; +#ifdef EXT_ASC + text = text_in; +#else + { + const size_t n_char_text = strlen(text_in); + text = TMALLOC(char, n_char_text); + utf8_to_latin9(text, text_in, n_char_text); + } #endif /* set linestyle to solid or may get funny color text on some plotters */ @@ -410,12 +422,12 @@ int PS_Text(char *text, int x, int y, int angle) PS_SetLinestyle(SOLID); /* set text color to black if background is not white */ if (setbgcolor > 0) - PS_SetColor(0, currentgraph); + PS_SetColor(0); else - PS_SetColor(1, currentgraph); + PS_SetColor(1); /* if color is given by set hcopytxpscolor=settxcolor, give it a try */ if (settxcolor >= 0) - PS_SetColor(settxcolor, currentgraph); + PS_SetColor(settxcolor); /* stroke the path if there's an open one */ PS_Stroke(); /* move to (x, y) */ @@ -431,8 +443,13 @@ int PS_Text(char *text, int x, int y, int angle) /* restore old linestyle */ - PS_SetColor(savedcolor, currentgraph); + PS_SetColor(savedcolor); PS_SetLinestyle(savedlstyle); + +#ifndef EXT_ASC + txfree(text); +#endif + return 0; } @@ -458,9 +475,8 @@ int PS_SetLinestyle(int linestyleid) } -int PS_SetColor(int colorid, GRAPH *graph) +int PS_SetColor(int colorid) { - NG_IGNORE(graph); PS_LinestyleColor(currentgraph->linestyle, colorid); return 0; } @@ -600,7 +616,8 @@ static inline unsigned int to_latin9(const unsigned int code) * Output has to have room for (length+1) chars, including the trailing NUL byte. from http://stackoverflow.com/questions/11156473/is-there-a-way-to-convert-from-utf8-to-iso-8859-1#11173493 */ -size_t utf8_to_latin9(char *const output, const char *const input, const size_t length) +size_t utf8_to_latin9(char * const output, const char *const input, + const size_t length) { unsigned char *out = (unsigned char *)output; const unsigned char *in = (const unsigned char *)input; diff --git a/src/frontend/rawfile.c b/src/frontend/rawfile.c index 38dc60684..8767b0064 100644 --- a/src/frontend/rawfile.c +++ b/src/frontend/rawfile.c @@ -464,7 +464,11 @@ raw_read(char *name) { } s = SKIP(buf); if (!*s) { - (void) fgets(buf, BSIZE_SP, fp); + if (fgets(buf, BSIZE_SP, fp) == (char *) NULL) { + fprintf(cp_err, "Error: unable to read line\n"); + plots = NULL; + break; + } s = buf; } if (numdims == 0) { @@ -490,7 +494,10 @@ raw_read(char *name) { if (!i) { curpl->pl_scale = v; } else { - (void) fgets(buf, BSIZE_SP, fp); + if (fgets(buf, BSIZE_SP, fp) == (char *) NULL) { + fprintf(cp_err, "Error: unable to read variable line\n"); + break; + } s = buf; } s = nexttok(s); /* The strchr field. */ @@ -591,7 +598,10 @@ raw_read(char *name) { for (i = 0; i < npoints; i++) { if (is_ascii) { /* It's an ASCII file. */ - (void) fscanf(fp, " %d", &j); + if (fscanf(fp, " %d", &j) != 1) { + fprintf(cp_err, "Error: unable to read point count\n"); + break; + } for (v = curpl->pl_dvecs; v; v = v->v_next) { if (i < v->v_length) { if (flags & VF_REAL) { @@ -657,7 +667,7 @@ raw_read(char *name) { return (NULL); } } - } + } /* end of loop */ if (curpl) { /* reverse commands list */ for (wl = curpl->pl_commands, curpl->pl_commands = NULL; diff --git a/src/frontend/resource.c b/src/frontend/resource.c index 37d07b6c1..703bf83ee 100644 --- a/src/frontend/resource.c +++ b/src/frontend/resource.c @@ -61,13 +61,15 @@ static void fprintmem(FILE *stream, unsigned long long memory); #if defined(HAVE_WIN32) || defined(HAVE__PROC_MEMINFO) static int get_procm(struct proc_mem *memall); -static int get_sysmem(struct sys_mem *memall); struct sys_mem mem_t, mem_t_act; struct proc_mem mem_ng, mem_ng_act; #endif +#if defined(HAVE_WIN32) && defined(SHARED_MODULE) && defined(__MINGW32__) +static int get_sysmem(struct sys_mem *memall); +#endif void init_rlimits(void) @@ -431,10 +433,13 @@ static int get_procm(struct proc_mem *memall) { } else return 0; #else -/* Use Windows GlobalMemoryStatus or /proc/memory to obtain size of memory - not accurate */ - get_sysmem(&mem_t_act); /* size is the difference between free memory at start time and now */ + /* Use Windows GlobalMemoryStatus or /proc/memory to obtain size of memory - + * not accurate */ + get_sysmem(&mem_t_act); /* size is the difference between free memory at + * start time and now */ if (mem_t.free > mem_t_act.free) /* it can happen that that ngspice is */ - memall->size = (mem_t.free - mem_t_act.free); /* to small compared to os memory usage */ + memall->size = (mem_t.free - mem_t_act.free); /* too small compared to + * os memory usage */ else memall->size = 0; /* sure, it is more */ memall->resident = 0; @@ -476,8 +481,8 @@ static int get_procm(struct proc_mem *memall) { } -static int -get_sysmem(struct sys_mem *memall) +#if defined(HAVE_WIN32) && defined(SHARED_MODULE) && defined(__MINGW32__) +static int get_sysmem(struct sys_mem *memall) { #ifdef HAVE_WIN32 #if (_WIN32_WINNT >= 0x0500) @@ -542,6 +547,7 @@ get_sysmem(struct sys_mem *memall) #endif return 1; } +#endif #else diff --git a/src/frontend/resource.h b/src/frontend/resource.h index 15b99c399..c3d27a844 100644 --- a/src/frontend/resource.h +++ b/src/frontend/resource.h @@ -6,6 +6,8 @@ #ifndef ngspice_RESOURCE_H #define ngspice_RESOURCE_H +#include "ngspice/wordlist.h" + extern unsigned long long getMemorySize(void); extern unsigned long long getPeakRSS(void); extern unsigned long long getCurrentRSS(void); diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index 23f36fec1..9683d3fb1 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -1386,7 +1386,11 @@ void com_snload(wordlist *wl) return; } - fread(&tmpI, sizeof(int), 1, file); + if (fread(&tmpI, sizeof(int), 1, file) != 1) { + (void) fprintf(cp_err, "Unable to read spice version from snapshot.\n"); + fclose(file); + return; + } if (tmpI != sizeof(CKTcircuit)) { fprintf(cp_err, "loaded num: %d, expected num: %ld\n", tmpI, (long)sizeof(CKTcircuit)); fprintf(cp_err, "Error: snapshot saved with different version of spice\n"); @@ -1396,7 +1400,11 @@ void com_snload(wordlist *wl) my_ckt = TMALLOC(CKTcircuit, 1); - fread(my_ckt, sizeof(CKTcircuit), 1, file); + if (fread(my_ckt, sizeof(CKTcircuit), 1, file) != 1) { + (void) fprintf(cp_err, "Unable to read spice circuit from snapshot.\n"); + fclose(file); + return; + } #define _t(name) ckt->name = my_ckt->name #define _ta(name, size) \ @@ -1484,17 +1492,24 @@ void com_snload(wordlist *wl) #define _foo(name, type, _size) \ do { \ int __i; \ - fread(&__i, sizeof(int), 1, file); \ - if (__i) { \ - if (name) \ - tfree(name); \ - name = (type *)tmalloc((size_t) __i); \ - fread(name, 1, (size_t) __i, file); \ - } else { \ + if (fread(&__i, sizeof(int), 1, file) == 1 && __i > 0) { \ + if (name) { \ + txfree(name); \ + } \ + name = (type *) tmalloc((size_t) __i); \ + if (fread(name, 1, (size_t) __i, file) != (size_t) __i) { \ + (void) fprintf(cp_err, \ + "Unable to read vector " #name "\n"); \ + break; \ + } \ + } \ + else { \ fprintf(cp_err, "size for vector " #name " is 0\n"); \ } \ - if ((_size) != -1 && __i != (_size) * (int)sizeof(type)) { \ - fprintf(cp_err, "expected %ld, but got %d for "#name"\n", (_size)*(long)sizeof(type), __i); \ + if ((_size) != -1 && __i != \ + (int) (_size) * (int) sizeof(type)) { \ + fprintf(cp_err, "expected %ld, but got %d for "#name"\n", \ + (_size)*(long)sizeof(type), __i); \ } \ } while(0) diff --git a/src/frontend/terminal.c b/src/frontend/terminal.c index d29384e12..98c58f8ed 100644 --- a/src/frontend/terminal.c +++ b/src/frontend/terminal.c @@ -21,14 +21,12 @@ Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group #include #endif -#if 0 -/* Bad interaction with bool type in bool.h because curses also - defines this symbol. */ + #ifdef HAVE_TERMCAP #include #include #endif -#endif + #ifdef HAVE_TERMCAP_H #include @@ -129,7 +127,7 @@ outbufputc(void) { if (ourbuf.count != BUFSIZ) { fputs(staticbuf, cp_out); - memset(staticbuf, 0, (size_t) BUFSIZ - ourbuf.count); + memset(staticbuf, 0, (size_t) (BUFSIZ - ourbuf.count)); ourbuf.count = BUFSIZ; ourbuf.ptr = staticbuf; } diff --git a/src/frontend/typesdef.c b/src/frontend/typesdef.c index 13703b2df..b15c389f0 100644 --- a/src/frontend/typesdef.c +++ b/src/frontend/typesdef.c @@ -75,7 +75,7 @@ static struct plotab plotabs[NUMPLOTTYPES] = { { "ac", "ac", FALSE, FALSE }, { "pz", "pz", FALSE, FALSE }, { "pz", "p.z.", FALSE, FALSE }, - { "pz", "pole-zero", FALSE}, + { "pz", "pole-zero", FALSE, FALSE}, { "disto", "disto", FALSE, FALSE }, { "dist", "dist", FALSE, FALSE }, { "noise", "noise", FALSE, FALSE }, diff --git a/src/frontend/vectors.c b/src/frontend/vectors.c index 99bb47d77..a7fee8b74 100644 --- a/src/frontend/vectors.c +++ b/src/frontend/vectors.c @@ -463,7 +463,8 @@ struct dvec *vec_fromplot(char *word, struct plot *plot) { DS_CREATE(ds, 100); const char * const node_start = word + 2; bool ds_ok = ds_cat_mem(&ds, node_start, - p_last_close_paren - node_start) == DS_E_OK; + (size_t) (p_last_close_paren - node_start)) == + DS_E_OK; /* If i(node) or I(node), append #branch */ if (tolower(word[0]) == (int) 'i') { /* i(node) or I(node) */ @@ -809,7 +810,8 @@ struct dvec *vec_copy(struct dvec *v) { nv->v_numdims = v->v_numdims; /* Copy defined dimensions */ - (void) memcpy(nv->v_dims, v->v_dims, v->v_numdims * sizeof *v->v_dims); + (void) memcpy(nv->v_dims, v->v_dims, + (size_t) v->v_numdims * sizeof *v->v_dims); nv->v_plot = v->v_plot; nv->v_next = NULL; @@ -1286,10 +1288,10 @@ vec_mkfamily(struct dvec *v) { d->v_dims[0] = size; if (isreal(v)) { - memcpy(d->v_realdata, v->v_realdata + (size_t) size * i, + memcpy(d->v_realdata, v->v_realdata + (size_t) (size * i), (size_t) size * sizeof(double)); } else { - memcpy(d->v_compdata, v->v_compdata + (size_t) size * i, + memcpy(d->v_compdata, v->v_compdata + (size_t) (size * i), (size_t) size * sizeof(ngcomplex_t)); } /* Add one to the counter. */ diff --git a/src/frontend/wdisp/windisp.c b/src/frontend/wdisp/windisp.c index 9ed9df0df..3863a847b 100644 --- a/src/frontend/wdisp/windisp.c +++ b/src/frontend/wdisp/windisp.c @@ -693,16 +693,17 @@ int WIN_NewViewport(GRAPH *graph) 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); #else /* UTF-8 support */ - wchar_t *wtext, *wtext2; - wtext = TMALLOC(wchar_t, 2 * strlen(graph->plotname) + 1); - wtext2 = TMALLOC(wchar_t, 2 * strlen(WindowName) + 1); + const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1; + wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + const int n_byte_wide2 = 2 * (int) strlen(WindowName) + 1; + wchar_t * const wtext2 = TMALLOC(wchar_t, n_byte_wide2); /* translate UTF-8 to UTF-16 */ - MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, 2 * strlen(graph->plotname) + 1); - MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, 2 * strlen(WindowName) + 1); + MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, n_byte_wide); + MultiByteToWideChar(CP_UTF8, 0, WindowName, -1, wtext2, n_byte_wide2); window = CreateWindowW(wtext2, wtext, WS_OVERLAPPEDWINDOW, 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); - tfree(wtext); - tfree(wtext2); + txfree(wtext); + txfree(wtext2); #endif if (!window) return 1; @@ -733,7 +734,7 @@ int WIN_NewViewport(GRAPH *graph) wd->PaintFlag = 0; wd->FirstFlag = 1; - /* modify system menue */ + /* modify system menu */ sysmenu = GetSystemMenu(window, FALSE); AppendMenu(sysmenu, MF_SEPARATOR, 0, NULL); AppendMenu(sysmenu, MF_STRING, ID_DRUCKEN, STR_DRUCKEN); @@ -956,7 +957,7 @@ WIN_Text_old(char *text, int x, int y, int degrees) #endif -int WIN_Text(char *text, int x, int y, int angle) +int WIN_Text(const char *text, int x, int y, int angle) { tpWindowData wd; HFONT hfont; @@ -1042,11 +1043,12 @@ int WIN_Text(char *text, int x, int y, int angle) #ifdef EXT_ASC TextOut(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, text, (int)strlen(text)); #else - wchar_t *wtext; - wtext = TMALLOC(wchar_t, 2 * strlen(text) + 1); - MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 2 * strlen(text) + 1); - TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, wtext, 2 * (int)strlen(text) + 1); - tfree(wtext); + const int n_byte_wide = 2 * (int) strlen(text) + 1; + wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide); + TextOutW(wd->hDC, x, wd->Area.bottom - y - currentgraph->fontheight, + wtext, n_byte_wide); + txfree(wtext); #endif DeleteObject(SelectObject(wd->hDC, hfont)); @@ -1079,9 +1081,8 @@ int WIN_SetLinestyle(int style) } -int WIN_SetColor(int color, GRAPH *graph) +int WIN_SetColor(int color) { - NG_IGNORE(graph); tpWindowData wd; if (!currentgraph) diff --git a/src/frontend/wdisp/winprint.c b/src/frontend/wdisp/winprint.c index de07b1f3a..4ddda2651 100644 --- a/src/frontend/wdisp/winprint.c +++ b/src/frontend/wdisp/winprint.c @@ -294,13 +294,15 @@ int WPRINT_NewViewport(GRAPH * graph) TextOut(PrinterDC, PrinterWidth - graph->fontwidth, 1, graph->plotname, (int)strlen(graph->plotname)); #else - wchar_t* wtext; - wtext = TMALLOC(wchar_t, 2 * strlen(graph->plotname) + 1); - MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, 2 * strlen(graph->plotname) + 1); - TextOutW(PrinterDC, PrinterWidth - graph->fontwidth, 1, wtext, 2 * (int)strlen(graph->plotname) + 1); - tfree(wtext); + const int n_byte_wide = 2 * (int) strlen(graph->plotname) + 1; + wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + MultiByteToWideChar(CP_UTF8, 0, graph->plotname, -1, wtext, + n_byte_wide); + TextOutW(PrinterDC, PrinterWidth - graph->fontwidth, 1, wtext, + n_byte_wide); + txfree(wtext); #endif - SetTextAlign( PrinterDC, align); + SetTextAlign(PrinterDC, align); } /* fertig */ @@ -431,11 +433,12 @@ int WPRINT_Text(char * text, int x, int y, int degrees) #ifdef EXT_ASC TextOut(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, text, (int)strlen(text)); #else - wchar_t* wtext; - wtext = TMALLOC(wchar_t, 2 * strlen(text) + 1); - MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, 2 * strlen(text) + 1); - TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, wtext, 2 * (int)strlen(text) + 1); - tfree(wtext); + const int n_byte_wide = 2 * (int) strlen(text) + 1; + wchar_t * const wtext = TMALLOC(wchar_t, n_byte_wide); + MultiByteToWideChar(CP_UTF8, 0, text, -1, wtext, n_byte_wide); + TextOutW(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, + wtext, n_byte_wide); + txfree(wtext); #endif return (0); } diff --git a/src/include/ngspice/cidersupt.h b/src/include/ngspice/cidersupt.h index 2101f3549..c7f79b101 100644 --- a/src/include/ngspice/cidersupt.h +++ b/src/include/ngspice/cidersupt.h @@ -7,9 +7,12 @@ #ifndef ngspice_CIDERSUPT_H #define ngspice_CIDERSUPT_H -#include "ngspice/numglobs.h" -#include "ngspice/material.h" +#include + +#include "ngspice/bool.h" #include "ngspice/gendev.h" +#include "ngspice/material.h" +#include "ngspice/numglobs.h" #include "ngspice/profile.h" /* externals for database.c */ @@ -60,21 +63,21 @@ extern void printMaterialInfo(MaterialInfo * ); /* externals for mobil.c */ extern void MOBdefaults(MaterialInfo *, int, int, int, int ); -extern void MOBtempDep (MaterialInfo *, double ); -extern void MOBconcDep (MaterialInfo *, double, double *, double *); -extern void MOBfieldDep (MaterialInfo *, int, double, double *, double * ); +extern void MOBtempDep(MaterialInfo *, double ); +extern void MOBconcDep(MaterialInfo *, double, double *, double *); +extern void MOBfieldDep(MaterialInfo *, int, double, double *, double * ); /* externals for recomb.c */ -extern void recomb (double, double, double, double, double, double, +extern void recomb(double, double, double, double, double, double, double, double *, double *, double * ); /* externals for suprem.c */ -extern void readAsciiData( char *, int, DOPtable ** ); -extern void readSupremData( char *, int, int, DOPtable ** ); +extern int readAsciiData(const char *, int, DOPtable **); +extern int readSupremData(const char *, int, int, DOPtable ** ); /* externals for suprmitf.c */ -extern void SUPbinRead( char *, float *, float *, int *, int * ); -extern void SUPascRead( char *, float *, float *, int *, int * ); +extern int SUPbinRead(const char *, float *, float *, int *, int *); +extern int SUPascRead(const char *, float *, float *, int *, int *); diff --git a/src/include/ngspice/cmproto.h b/src/include/ngspice/cmproto.h index 2855fa0c8..c806e43c2 100644 --- a/src/include/ngspice/cmproto.h +++ b/src/include/ngspice/cmproto.h @@ -114,8 +114,6 @@ int cm_message_printf(const char *fmt, ...) int cm_message_printf(const char *fmt, ...); #endif -#ifndef CM_IGNORE -#define CM_IGNORE(x) (x) -#endif +#define CM_IGNORE(x) (void) (x) -#endif +#endif /* include guard */ diff --git a/src/include/ngspice/complex.h b/src/include/ngspice/complex.h index 9ed79eac7..cecaa0106 100644 --- a/src/include/ngspice/complex.h +++ b/src/include/ngspice/complex.h @@ -69,13 +69,17 @@ typedef struct { #endif /* Some defines used mainly in cmath.c. */ -#define cph(c) (atan2(imagpart(c), (realpart(c)))) -#define cmag(c) (hypot(realpart(c), imagpart(c))) +#define cph(c) (atan2(imagpart(c), (realpart(c)))) +#define cmag(c) (hypot(realpart(c), imagpart(c))) #define radtodeg(c) (cx_degrees ? ((c) * (180 / M_PI)) : (c)) #define degtorad(c) (cx_degrees ? ((c) * (M_PI / 180)) : (c)) -#define rcheck(cond, name) if (!(cond)) { \ - fprintf(cp_err, "Error: argument out of range for %s\n", name); \ - return (NULL); } +#define rcheck(cond, name)\ + if (!(cond)) {\ + (void) fprintf(cp_err, "Error: argument out of range for %s\n",\ + name);\ + xrc = -1;\ + goto EXITPOINT;\ + } #define cdiv(r1, i1, r2, i2, r3, i3) \ diff --git a/src/include/ngspice/cpdefs.h b/src/include/ngspice/cpdefs.h index 7dbfa713f..5ae7e2b6c 100644 --- a/src/include/ngspice/cpdefs.h +++ b/src/include/ngspice/cpdefs.h @@ -41,7 +41,7 @@ struct comm { int co_maxargs; /* The fn that prompts the user. */ - void (*co_argfn) (wordlist *wl, struct comm *command); + void (*co_argfn)(const wordlist *wl, const struct comm *command); /* When these are printed, printf(string, av[0]) .. */ char *co_help; diff --git a/src/include/ngspice/cpstd.h b/src/include/ngspice/cpstd.h index aab9409f9..b5e973000 100644 --- a/src/include/ngspice/cpstd.h +++ b/src/include/ngspice/cpstd.h @@ -26,7 +26,6 @@ Author: 1986 Wayne A. Christopher, U. C. Berkeley CAD Group /* Externs defined in std.c */ -extern char *tildexpand(const char *string); extern void printnum(char *buf, double num); int printnum_ds(DSTRING *p_ds, double num); extern int cp_numdgt; diff --git a/src/include/ngspice/devdefs.h b/src/include/ngspice/devdefs.h index 49704ab07..ead0d29dd 100644 --- a/src/include/ngspice/devdefs.h +++ b/src/include/ngspice/devdefs.h @@ -55,15 +55,15 @@ typedef struct SPICEdev { /* routine to input a paramater to a model */ int (*DEVload)(GENmodel*,CKTcircuit*); /* routine to load the device into the matrix */ - int (*DEVsetup)(SMPmatrix*,GENmodel*,CKTcircuit*,int*); + int (*DEVsetup)(SMPmatrix *, GENmodel *, CKTcircuit *, int *); /* setup routine to preprocess devices once before soloution begins */ int (*DEVunsetup)(GENmodel*,CKTcircuit*); /* clean up before running again */ - int (*DEVpzSetup)(SMPmatrix*,GENmodel*,CKTcircuit*,int*); + int (*DEVpzSetup)(SMPmatrix *, GENmodel *, CKTcircuit *, int *); /* setup routine to process devices specially for pz analysis */ - int (*DEVtemperature)(GENmodel*,CKTcircuit*); + int (*DEVtemperature)(GENmodel*,CKTcircuit*); /* subroutine to do temperature dependent setup processing */ - int (*DEVtrunc)(GENmodel*,CKTcircuit*,double*); + int (*DEVtrunc)(GENmodel*,CKTcircuit*,double*); /* subroutine to perform truncation error calc. */ int (*DEVfindBranch)(CKTcircuit*,GENmodel*,IFuid); /* subroutine to search for device branch eq.s */ diff --git a/src/include/ngspice/ftedev.h b/src/include/ngspice/ftedev.h index 530f497ac..1dbba6194 100644 --- a/src/include/ngspice/ftedev.h +++ b/src/include/ngspice/ftedev.h @@ -10,6 +10,9 @@ Author: 1987 Jeffrey M. Hsu #ifndef ngspice_FTEDEV_H #define ngspice_FTEDEV_H +#include "ngspice/bool.h" +#include "ngspice/typedefs.h" + struct graph; struct request; struct response; @@ -20,11 +23,11 @@ typedef int disp_fn_Close_t (void); typedef int disp_fn_Clear_t (void); typedef int disp_fn_DrawLine_t (int x1, int y1, int x2, int y2, bool isgrid); typedef int disp_fn_Arc_t (int x0, int y0, int radius, double theta, double delta_theta); -typedef int disp_fn_Text_t (char *text, int x, int y, int angle); +typedef int disp_fn_Text_t (const char *text, int x, int y, int angle); typedef int disp_fn_DefineColor_t (int colorid, double red, double green, double blue); typedef int disp_fn_DefineLinestyle_t (int linestyleid, int mask); typedef int disp_fn_SetLinestyle_t (int linestyleid); -typedef int disp_fn_SetColor_t (int colorid, GRAPH *graf); +typedef int disp_fn_SetColor_t (int colorid); typedef int disp_fn_Update_t (void); typedef int disp_fn_Track_t (void); typedef int disp_fn_MakeMenu_t (void); diff --git a/src/include/ngspice/mifproto.h b/src/include/ngspice/mifproto.h index edf125988..825c8ebb3 100644 --- a/src/include/ngspice/mifproto.h +++ b/src/include/ngspice/mifproto.h @@ -156,7 +156,7 @@ extern char *MIFcopy(const char *); #ifndef CM_IGNORE -#define CM_IGNORE(x) (x) +#define CM_IGNORE(x) (void) (x) #endif -#endif +#endif /* include guard */ diff --git a/src/main.c b/src/main.c index 7126766ce..4aadd86bd 100644 --- a/src/main.c +++ b/src/main.c @@ -544,14 +544,18 @@ prompt(void) s = "->"; while (*s) { - char c = (char) (*s++); + char c = (*s++); + + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch (c) { case '!': p += sprintf(p, "%d", where_history() + 1); break; - case '\\': + case '\\': /* skip an escape char */ if (*s) c = (char) (*s++); + /* FALLTHROUGH */ default: *p++ = c; break; @@ -799,8 +803,11 @@ int main(int argc, char **argv) { char log_file[BSIZE_SP]; char soa_log_file[BSIZE_SP]; - bool readinit = TRUE; /* read initialization file */ - bool istty = TRUE; + + /* volatile added to resolve GCC -Wclobbered */ + volatile bool readinit = TRUE; /* read initialization file */ + volatile bool istty = TRUE; + bool iflag = FALSE; /* flag for interactive mode */ bool qflag = FALSE; /* flag for command completion */ @@ -910,7 +917,7 @@ int main(int argc, char **argv) } else { DS_CREATE(ds, 100); - if (ds_cat_mem(&ds, optarg, eq - optarg) == 0) { + if (ds_cat_mem(&ds, optarg, (size_t) (eq - optarg)) == 0) { cp_vset(ds_get_buf(&ds), CP_STRING, eq + 1); } ds_free(&ds); diff --git a/src/maths/cmaths/cmath1.c b/src/maths/cmaths/cmath1.c index 34a5409c6..a1fbb0cb4 100644 --- a/src/maths/cmaths/cmath1.c +++ b/src/maths/cmaths/cmath1.c @@ -16,6 +16,8 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group * */ +#include + #include "ngspice/ngspice.h" #include "ngspice/memory.h" #include "ngspice/cpdefs.h" @@ -206,7 +208,7 @@ void *cx_conj(void *data, short int type, int length, ngcomplex_t * const c_dst = alloc_c(length); ngcomplex_t *c_dst_cur = c_dst; ngcomplex_t *c_src_cur = (ngcomplex_t *) data; - ngcomplex_t * const c_src_end = c_src_cur + length; + ngcomplex_t * const c_src_end = c_src_cur + length; for ( ; c_src_cur < c_src_end; c_src_cur++, c_dst_cur++) { c_dst_cur->cx_real = c_src_cur->cx_real; c_dst_cur->cx_imag = -c_src_cur->cx_imag; @@ -215,7 +217,7 @@ void *cx_conj(void *data, short int type, int length, } /* Else real, so just copy */ - return memcpy(alloc_d(length), data, length * sizeof(double)); + return memcpy(alloc_d(length), data, (unsigned int) length * sizeof(double)); } /* end of function cx_conj */ @@ -241,20 +243,19 @@ cx_pos(void *data, short int type, int length, int *newlength, short int *newtyp return ((void *) d); } -void * -cx_db(void *data, short int type, int length, int *newlength, short int *newtype) +void *cx_db(void *data, short int type, int length, + int *newlength, short int *newtype) { + int xrc = 0; double *d = alloc_d(length); - double *dd = (double *) data; - ngcomplex_t *cc = (ngcomplex_t *) data; - double tt; - int i; *newlength = length; *newtype = VF_REAL; - if (type == VF_COMPLEX) + if (type == VF_COMPLEX) { + ngcomplex_t *cc = (ngcomplex_t *) data; + int i; for (i = 0; i < length; i++) { - tt = cmag(cc[i]); + const double tt = cmag(cc[i]); rcheck(tt > 0, "db"); /* if (tt == 0.0) @@ -263,29 +264,44 @@ cx_db(void *data, short int type, int length, int *newlength, short int *newtype */ d[i] = 20.0 * log10(tt); } - else + } + else { + double *dd = (double *) data; + int i; for (i = 0; i < length; i++) { - rcheck(dd[i] > 0, "db"); + const double tt = dd[i]; + rcheck(tt > 0, "db"); /* if (dd[i] == 0.0) d[i] = 20.0 * - log(HUGE); else */ - d[i] = 20.0 * log10(dd[i]); + d[i] = 20.0 * log10(tt); } - return ((void *) d); -} + } -void * -cx_log10(void *data, short int type, int length, int *newlength, short int *newtype) +EXITPOINT: + if (xrc != 0) { + txfree(d); + d = (double *) NULL; + } + return ((void *) d); +} /* end of function cx_db */ + + + +void *cx_log10(void *data, short int type, int length, + int *newlength, short int *newtype) { - *newlength = length; + int xrc = 0; + void *rv; + if (type == VF_COMPLEX) { ngcomplex_t *c; ngcomplex_t *cc = (ngcomplex_t *) data; int i; - c = alloc_c(length); + rv = c = alloc_c(length); *newtype = VF_COMPLEX; for (i = 0; i < length; i++) { double td; @@ -298,42 +314,58 @@ cx_log10(void *data, short int type, int length, int *newlength, short int *newt if (td == 0.0) { realpart(c[i]) = - log10(HUGE); imagpart(c[i]) = 0.0; - } else { + } + else { realpart(c[i]) = log10(td); - imagpart(c[i]) = atan2(imagpart(cc[i]), - realpart(cc[i])); + imagpart(c[i]) = atan2(imagpart(cc[i]), realpart(cc[i])); } } - return ((void *) c); - } else { + } + else { double *d; double *dd = (double *) data; int i; - d = alloc_d(length); + rv = d = alloc_d(length); *newtype = VF_REAL; for (i = 0; i < length; i++) { rcheck(dd[i] >= 0, "log10"); - if (dd[i] == 0.0) + if (dd[i] == 0.0) { d[i] = - log10(HUGE); - else + } + else { d[i] = log10(dd[i]); + } } - return ((void *) d); } -} -void * -cx_log(void *data, short int type, int length, int *newlength, short int *newtype) -{ *newlength = length; + +EXITPOINT: + if (xrc != 0) { /* Free resources on error */ + txfree(rv); + rv = NULL; + } + + return rv; +} /* end of function cx_log10 */ + + + +void *cx_log(void *data, short int type, int length, + int *newlength, short int *newtype) +{ + int xrc = 0; + void *rv; + if (type == VF_COMPLEX) { ngcomplex_t *c; ngcomplex_t *cc = (ngcomplex_t *) data; - int i; - c = alloc_c(length); + rv = c = alloc_c(length); *newtype = VF_COMPLEX; + + int i; for (i = 0; i < length; i++) { double td; @@ -342,20 +374,21 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp if (td == 0.0) { realpart(c[i]) = - log(HUGE); imagpart(c[i]) = 0.0; - } else { + } + else { realpart(c[i]) = log(td); - imagpart(c[i]) = atan2(imagpart(cc[i]), - realpart(cc[i])); + imagpart(c[i]) = atan2(imagpart(cc[i]), realpart(cc[i])); } } - return ((void *) c); - } else { + } + else { double *d; double *dd = (double *) data; - int i; - d = alloc_d(length); + rv = d = alloc_d(length); *newtype = VF_REAL; + + int i; for (i = 0; i < length; i++) { rcheck(dd[i] >= 0, "log"); if (dd[i] == 0.0) @@ -363,9 +396,20 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp else d[i] = log(dd[i]); } - return ((void *) d); } -} + + *newlength = length; + +EXITPOINT: + if (xrc != 0) { /* Free resources on error */ + txfree(rv); + rv = NULL; + } + + return rv; +} /* end of function cx_log */ + + void * cx_exp(void *data, short int type, int length, int *newlength, short int *newtype) @@ -614,19 +658,29 @@ cx_cosh(void *data, short int type, int length, int *newlength, short int *newty } } -static double * -d_tan(double *dd, int length) -{ - double *d; - int i; - d = alloc_d(length); + +static double *d_tan(double *dd, int length) +{ + int xrc = 0; + double *d = alloc_d(length); + + int i; for (i = 0; i < length; i++) { rcheck(tan(degtorad(dd[i])) != 0, "tan"); d[i] = tan(degtorad(dd[i])); } + +EXITPOINT: + if (xrc != 0) { /* Free resources on error */ + txfree(d); + d = (double *) NULL; + } + return d; -} +} /* end of function d_tan */ + + static double * d_tanh(double *dd, int length) @@ -641,64 +695,94 @@ d_tanh(double *dd, int length) return d; } -static ngcomplex_t * -c_tan(ngcomplex_t *cc, int length) +/* See https://proofwiki.org/wiki/Tangent_of_Complex_Number (formulation 4) among + * others for the tangent formula: + + * sin z = sin(x + iy) = sin x cos(iy) + cos x sin(iy) = sin x cosh y + i cos x sinh y + * cos z = cos(x + iy) = cos x cos(iy) + sin x sin(iy) = cos x cosh y - i sin x sinh y + * tan z = ((sin x cosh y + i cos x sinh y) / (cos x cosh y - i sin x sinh y)) * + (cos x cosh y + isin x sinh y) / (cos x cosh y + i sin x sinh y) + = ... + * + * + * tan(a + bi) = (sin(2a) + i * sinh(2b)) / (cos(2a) + cosh(2b)) + */ +static ngcomplex_t *c_tan(ngcomplex_t *cc, int length) { - ngcomplex_t *c; + ngcomplex_t * const c = alloc_c(length); + int i; - - c = alloc_c(length); for (i = 0; i < length; i++) { - double u, v; - - rcheck(cos(degtorad(realpart(cc[i]))) * - cosh(degtorad(imagpart(cc[i]))), "tan"); - rcheck(sin(degtorad(realpart(cc[i]))) * - sinh(degtorad(imagpart(cc[i]))), "tan"); - u = degtorad(realpart(cc[i])); - v = degtorad(imagpart(cc[i])); - /* The Lattice C compiler won't take multi-line macros, and - * CMS won't take >80 column lines.... - */ -#define xx1 sin(u) * cosh(v) -#define xx2 cos(u) * sinh(v) -#define xx3 cos(u) * cosh(v) -#define xx4 -sin(u) * sinh(v) - cdiv(xx1, xx2, xx3, xx4, realpart(c[i]), imagpart(c[i])); - } - return c; -} - -/* complex tanh function, uses tanh(z) = -i * tan (i * z) */ -static ngcomplex_t * -c_tanh(ngcomplex_t *cc, int length) -{ - ngcomplex_t *c, *s, *t; - int i; - - c = alloc_c(length); - s = alloc_c(1); - t = alloc_c(1); - - for (i = 0; i < length; i++) { - /* multiply by i */ - t[0].cx_real = -1. * imagpart(cc[i]); - t[0].cx_imag = realpart(cc[i]); - /* get complex tangent */ - s = c_tan(t, 1); - /* if check in c_tan fails */ - if (s == NULL) { - tfree(t); - return (NULL); + errno = 0; + ngcomplex_t *p_dst = c + i; + ngcomplex_t *p_src = cc + i; + const double a = p_src->cx_real; + const double b = p_src->cx_imag; + const double u = 2 * degtorad(a); + const double v = 2 * degtorad(b); + const double n_r = sin(u); + const double n_i = sinh(v); + const double d1 = cos(u); + const double d2 = cosh(v); + const double d = d1 + d2; + if (errno != 0 || d == 0.0) { + (void) fprintf(cp_err, + "Invalid argument %lf + %lf i for compex tangent", a, b); + txfree(c); + return (ngcomplex_t *) NULL; } - /* multiply by -i */ - realpart(c[i]) = imagpart(s[0]); - imagpart(c[i]) = -1. * realpart(s[0]); - } - tfree(s); - tfree(t); + p_dst->cx_real = n_r / d; + p_dst->cx_imag = n_i / d; + } /* end of loop over elements in array */ + return c; -} +} /* end of function c_tan */ + + + +/* complex tanh function, uses tanh(z) = -i * tan(i * z). + * Unfortunately, it did so very inefficiently (a memory allocations per + * value calculated!) and leaked memory badly (all of the aforementioned + * allocations.) These issues were fixed 2020-03-04 */ +static ngcomplex_t *c_tanh(ngcomplex_t *cc, int length) +{ + ngcomplex_t * const tmp = alloc_c(length); /* i * z */ + + /* Build the i * z array to allow tan() to be called */ + { + int i; + for (i = 0; i < length; ++i) { + ngcomplex_t *p_dst = tmp + i; + ngcomplex_t *p_src = cc + i; + + /* multiply by i */ + p_dst->cx_real = -p_src->cx_imag; + p_dst->cx_imag = p_src->cx_real; + } + } + + /* Calculat tan(i * z), exiting on failure */ + ngcomplex_t *const c = c_tan(tmp, length); + if (c == (ngcomplex_t *) NULL) { + txfree(tmp); + return (ngcomplex_t *) NULL; + } + + /* Multiply by -i to find final result */ + { + int i; + for (i = 0; i < length; ++i) { + ngcomplex_t *p_cur = c + i; + const double cx_real = p_cur->cx_real; + p_cur->cx_real = p_cur->cx_imag; + p_cur->cx_imag = -cx_real; + } + } + + return c; +} /* end of function c_tanh */ + + void * cx_tan(void *data, short int type, int length, int *newlength, short int *newtype) @@ -770,8 +854,8 @@ cx_sortorder(void *data, short int type, int length, int *newlength, short int * double *dd = (double *) data; int i; - amplitude_index_t *array_amplitudes; - array_amplitudes = (amplitude_index_t *) tmalloc(sizeof(amplitude_index_t) * (size_t) length); + amplitude_index_t * const array_amplitudes = (amplitude_index_t *) + tmalloc(sizeof(amplitude_index_t) * (size_t) length); *newlength = length; *newtype = VF_REAL; @@ -788,7 +872,7 @@ cx_sortorder(void *data, short int type, int length, int *newlength, short int * d[i] = array_amplitudes[i].index; } - tfree(array_amplitudes); + txfree(array_amplitudes); /* Otherwise it is 0, but tmalloc zeros the stuff already. */ return ((void *) d); diff --git a/src/maths/cmaths/cmath2.c b/src/maths/cmaths/cmath2.c index 4f61e4860..0b94affaf 100644 --- a/src/maths/cmaths/cmath2.c +++ b/src/maths/cmaths/cmath2.c @@ -361,11 +361,17 @@ cx_avg(void *data, short int type, int length, int *newlength, short int *newtyp /* Compute the mean of a vector. */ -void * -cx_mean(void *data, short int type, int length, int *newlength, short int *newtype) +void *cx_mean(void *data, short int type, int length, + int *newlength, short int *newtype) { + if (length == 0) { + (void) fprintf(cp_err, "mean calculation requires " + "at least one element.\n"); + return NULL; + } + *newlength = 1; - rcheck(length > 0, "mean"); + if (type == VF_REAL) { double *d; double *dd = (double *) data; @@ -377,7 +383,8 @@ cx_mean(void *data, short int type, int length, int *newlength, short int *newty *d += dd[i]; *d /= length; return ((void *) d); - } else { + } + else { ngcomplex_t *c; ngcomplex_t *cc = (ngcomplex_t *) data; int i; @@ -397,43 +404,59 @@ cx_mean(void *data, short int type, int length, int *newlength, short int *newty /* Compute the standard deviation of all elements of a vector. */ -void * -cx_stddev(void *data, short int type, int length, int *newlength, short int *newtype) +void *cx_stddev(void *data, short int type, int length, + int *newlength, short int *newtype) { + if (length == 0) { + (void) fprintf(cp_err, "standard deviation calculation requires " + "at least one element.\n"); + return NULL; + } + *newlength = 1; - rcheck(length > 1, "stddev"); + if (type == VF_REAL) { - double *mean = (double *)cx_mean(data, type, length, newlength, newtype); - double *d, sum = 0.; - double *dd = (double *)data; - int i; + double *p_mean = (double *) cx_mean(data, type, length, + newlength, newtype); + double mean = *p_mean; + double *d, sum = 0.0; + double *dd = (double *) data; d = alloc_d(1); *newtype = VF_REAL; - for (i = 0; i < length; i++) - sum += (dd[i] - *mean) * (dd[i] - *mean); + int i; + for (i = 0; i < length; i++) { + const double tmp = dd[i] - mean; + sum += tmp * tmp; + } + *d = sqrt(sum / ((double) length - 1.0)); - tfree(mean); - return ((void *)d); + txfree(p_mean); + return (void *) d; } else { - ngcomplex_t *cmean = (ngcomplex_t *)cx_mean(data, type, length, newlength, newtype); - double *d, sum = 0., a, b; - ngcomplex_t *cc = (ngcomplex_t *)data; - int i; + ngcomplex_t * const p_cmean = (ngcomplex_t *) cx_mean(data, type, length, + newlength, newtype); + const ngcomplex_t cmean = *p_cmean; + const double rmean = realpart(cmean); + const double imean = imagpart(cmean); + double *d, sum = 0.0; + ngcomplex_t *cc = (ngcomplex_t *) data; d = alloc_d(1); *newtype = VF_REAL; + int i; for (i = 0; i < length; i++) { - a = realpart(cc[i]) - realpart(*cmean); - b = imagpart(cc[i]) - imagpart(*cmean); + const double a = realpart(cc[i]) - rmean; + const double b = imagpart(cc[i]) - imean; sum += a * a + b * b; } *d = sqrt(sum / ((double) length - 1.0)); - tfree(cmean); - return ((void *)d); + txfree(p_cmean); + return (void *) d; } -} +} /* end of function cx_stddev */ + void * @@ -635,35 +658,41 @@ cx_times(void *data1, void *data2, short int datatype1, short int datatype2, int } -void * -cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int length) +void *cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, + int length) { + int xrc = 0; + void *rv; double *dd1 = (double *) data1; double *dd2 = (double *) data2; - double *d; - ngcomplex_t *cc1 = (ngcomplex_t *) data1; - ngcomplex_t *cc2 = (ngcomplex_t *) data2; - ngcomplex_t *c, c1, c2; - int i, r1, r2, i1, i2, r3, i3; if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) { - d = alloc_d(length); + double *d; + rv = d = alloc_d(length); + + int i; for (i = 0; i < length; i++) { - r1 = (int)floor(fabs(dd1[i])); + const int r1 = (int) floor(fabs(dd1[i])); rcheck(r1 > 0, "mod"); - r2 = (int)floor(fabs(dd2[i])); + const int r2 = (int)floor(fabs(dd2[i])); rcheck(r2 > 0, "mod"); - r3 = r1 % r2; + const int r3 = r1 % r2; d[i] = (double) r3; } - return ((void *) d); - } else { - c = alloc_c(length); + } + else { + ngcomplex_t *c, c1, c2; + ngcomplex_t *cc1 = (ngcomplex_t *) data1; + ngcomplex_t *cc2 = (ngcomplex_t *) data2; + rv = c = alloc_c(length); + + int i; for (i = 0; i < length; i++) { if (datatype1 == VF_REAL) { realpart(c1) = dd1[i]; imagpart(c1) = 0.0; - } else { + } + else { c1 = cc1[i]; } if (datatype2 == VF_REAL) { @@ -672,34 +701,47 @@ cx_mod(void *data1, void *data2, short int datatype1, short int datatype2, int l } else { c2 = cc2[i]; } - r1 = (int)floor(fabs(realpart(c1))); + const int r1 = (int) floor(fabs(realpart(c1))); rcheck(r1 > 0, "mod"); - r2 = (int)floor(fabs(realpart(c2))); + const int r2 = (int) floor(fabs(realpart(c2))); rcheck(r2 > 0, "mod"); - i1 = (int)floor(fabs(imagpart(c1))); + const int i1 = (int) floor(fabs(imagpart(c1))); rcheck(i1 > 0, "mod"); - i2 = (int)floor(fabs(imagpart(c2))); + const int i2 = (int) floor(fabs(imagpart(c2))); rcheck(i2 > 0, "mod"); - r3 = r1 % r2; - i3 = i1 % i2; + const int r3 = r1 % r2; + const int i3 = i1 % i2; realpart(c[i]) = (double) r3; imagpart(c[i]) = (double) i3; } - return ((void *) c); } -} + +EXITPOINT: + if (xrc != 0) { /* Free resources on error */ + txfree(rv); + rv = NULL; + } + + return rv; +} /* end of function cx_mod */ + /* Routoure JM : Compute the max of a vector. */ -void * -cx_max(void *data, short int type, int length, int *newlength, short int *newtype) +void *cx_max(void *data, short int type, int length, + int *newlength, short int *newtype) { + if (length == 0) { + (void) fprintf(cp_err, "maximum calculation requires " + "at least one element.\n"); + return NULL; + } + *newlength = 1; - /* test if length >0 et affiche un message d'erreur */ - rcheck(length > 0, "mean"); + if (type == VF_REAL) { - double largest=0.0; + double largest = 0.0; double *d; double *dd = (double *) data; int i; @@ -707,14 +749,18 @@ cx_max(void *data, short int type, int length, int *newlength, short int *newtyp d = alloc_d(1); *newtype = VF_REAL; largest = dd[0]; - for (i = 1; i < length; i++) - if (largest < dd[i]) - largest = dd[i]; + for (i = 1; i < length; i++) { + const double tmp = dd[i]; + if (largest < tmp) { + largest = tmp; + } + } *d = largest; - return ((void *) d); - } else { - double largest_real=0.0; - double largest_complex=0.0; + return (void *) d; + } + else { + double largest_real = 0.0; + double largest_complex = 0.0; ngcomplex_t *c; ngcomplex_t *cc = (ngcomplex_t *) data; int i; @@ -723,27 +769,37 @@ cx_max(void *data, short int type, int length, int *newlength, short int *newtyp *newtype = VF_COMPLEX; largest_real = realpart(*cc); largest_complex = imagpart(*cc); - for (i = 0; i < length; i++) { - if (largest_real < realpart(cc[i])) - largest_real = realpart(cc[i]); - if (largest_complex < imagpart(cc[i])) - largest_complex = imagpart(cc[i]); + for (i = 1; i < length; i++) { + const double tmpr = realpart(cc[i]); + if (largest_real < tmpr) { + largest_real = tmpr; + } + const double tmpi = imagpart(cc[i]); + if (largest_complex < tmpi) { + largest_complex = tmpi; + } } realpart(*c) = largest_real; imagpart(*c) = largest_complex; - return ((void *) c); + return (void *) c; } -} +} /* end of function cx_max */ + /* Routoure JM : Compute the min of a vector. */ -void * -cx_min(void *data, short int type, int length, int *newlength, short int *newtype) +void *cx_min(void *data, short int type, int length, + int *newlength, short int *newtype) { + if (length == 0) { + (void) fprintf(cp_err, "minimum calculation requires " + "at least one element.\n"); + return NULL; + } + *newlength = 1; - /* test if length >0 et affiche un message d'erreur */ - rcheck(length > 0, "mean"); + if (type == VF_REAL) { double smallest; double *d; @@ -753,12 +809,16 @@ cx_min(void *data, short int type, int length, int *newlength, short int *newtyp d = alloc_d(1); *newtype = VF_REAL; smallest = dd[0]; - for (i = 1; i < length; i++) - if (smallest > dd[i]) - smallest = dd[i]; + for (i = 1; i < length; i++) { + const double tmp = dd[i]; + if (smallest > tmp) { + smallest = tmp; + } + } *d = smallest; - return ((void *) d); - } else { + return (void *) d; + } + else { double smallest_real; double smallest_complex; ngcomplex_t *c; @@ -770,26 +830,35 @@ cx_min(void *data, short int type, int length, int *newlength, short int *newtyp smallest_real = realpart(*cc); smallest_complex = imagpart(*cc); for (i = 1; i < length; i++) { - if (smallest_real > realpart(cc[i])) - smallest_real = realpart(cc[i]); - if (smallest_complex > imagpart(cc[i])) - smallest_complex = imagpart(cc[i]); + const double tmpr = realpart(cc[i]); + if (smallest_real > tmpr) { + smallest_real = tmpr; + } + const double tmpi = imagpart(cc[i]); + if (smallest_complex > tmpi) { + smallest_complex = tmpi; + } } realpart(*c) = smallest_real; imagpart(*c) = smallest_complex; - return ((void *) c); + return (void *) c; } -} +} /* end of function cx_min */ /* Routoure JM : Compute the differential of a vector. */ -void * -cx_d(void *data, short int type, int length, int *newlength, short int *newtype) +void *cx_d(void *data, short int type, int length, + int *newlength, short int *newtype) { + if (length == 0) { + (void) fprintf(cp_err, "differential calculation requires " + "at least one element.\n"); + return NULL; + } + *newlength = length; - /* test if length >0 et affiche un message d'erreur */ - rcheck(length > 0, "deriv"); + if (type == VF_REAL) { double *d; double *dd = (double *) data; @@ -799,12 +868,13 @@ cx_d(void *data, short int type, int length, int *newlength, short int *newtype) *newtype = VF_REAL; d[0] = dd[1] - dd[0]; d[length-1] = dd[length-1] - dd[length-2]; - for (i = 1; i < length - 1; i++) + for (i = 1; i < length - 1; i++) { d[i] = dd[i+1] - dd[i-1]; + } - return ((void *) d); - } else { - + return (void *) d; + } + else { ngcomplex_t *c; ngcomplex_t *cc = (ngcomplex_t *) data; int i; @@ -820,11 +890,11 @@ cx_d(void *data, short int type, int length, int *newlength, short int *newtype) for (i = 1; i < length - 1; i++) { realpart(c[i]) = realpart(cc[i+1]) - realpart(cc[i-1]); imagpart(c[i]) = imagpart(cc[i+1]) - imagpart(cc[i-1]); - } - return ((void *) c); + + return (void *) c; } -} +} /* end of function cx_d */ void * diff --git a/src/maths/cmaths/cmath3.c b/src/maths/cmaths/cmath3.c index 41e763479..e2903c54e 100644 --- a/src/maths/cmaths/cmath3.c +++ b/src/maths/cmaths/cmath3.c @@ -24,50 +24,64 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group static ngcomplex_t *cexp_sp3(ngcomplex_t *c); /* cexp exist's in some newer compiler */ -static ngcomplex_t *cln(ngcomplex_t *c); -static ngcomplex_t *ctimes(ngcomplex_t *c1, ngcomplex_t *c2); +static int cln(ngcomplex_t *c, ngcomplex_t *rv); +static void ctimes(ngcomplex_t *c1, ngcomplex_t *c2, ngcomplex_t *rv); -void * -cx_divide(void *data1, void *data2, short int datatype1, short int datatype2, int length) +void *cx_divide(void *data1, void *data2, + short int datatype1, short int datatype2, int length) { + int xrc = 0; + void *rv; double *dd1 = (double *) data1; double *dd2 = (double *) data2; - double *d; ngcomplex_t *cc1 = (ngcomplex_t *) data1; ngcomplex_t *cc2 = (ngcomplex_t *) data2; ngcomplex_t *c, c1, c2; int i; if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) { - d = alloc_d(length); + double *d; + rv = d = alloc_d(length); for (i = 0; i < length; i++) { rcheck(dd2[i] != 0, "divide"); d[i] = dd1[i] / dd2[i]; } - return ((void *) d); - } else { - c = alloc_c(length); + } + else { + rv = c = alloc_c(length); for (i = 0; i < length; i++) { if (datatype1 == VF_REAL) { realpart(c1) = dd1[i]; imagpart(c1) = 0.0; - } else { + } + else { c1 = cc1[i]; } if (datatype2 == VF_REAL) { realpart(c2) = dd2[i]; imagpart(c2) = 0.0; - } else { + } + else { c2 = cc2[i]; } rcheck((realpart(c2) != 0) || (imagpart(c2) != 0), "divide"); #define xx5 realpart(c1) #define xx6 imagpart(c1) -cdiv(xx5, xx6, realpart(c2), imagpart(c2), realpart(c[i]), imagpart(c[i])); + cdiv(xx5, xx6, realpart(c2), imagpart(c2), realpart(c[i]), + imagpart(c[i])); } - return ((void *) c); } -} + +EXITPOINT: + if (xrc != 0) { /* Free resources on error */ + tfree(rv); + rv = NULL; + } + + return rv; +} /* end of function cx_divide */ + + /* Should just use "j( )" */ /* The comma operator. What this does (unless it is part of the argument @@ -105,58 +119,82 @@ cx_comma(void *data1, void *data2, short int datatype1, short int datatype2, int return ((void *) c); } -void * -cx_power(void *data1, void *data2, short int datatype1, short int datatype2, int length) +void *cx_power(void *data1, void *data2, + short int datatype1, short int datatype2, int length) { + int xrc = 0; + void *rv; double *dd1 = (double *) data1; double *dd2 = (double *) data2; - double *d; - ngcomplex_t *cc1 = (ngcomplex_t *) data1; - ngcomplex_t *cc2 = (ngcomplex_t *) data2; - ngcomplex_t *c, c1, c2, *t; - int i; if ((datatype1 == VF_REAL) && (datatype2 == VF_REAL)) { - d = alloc_d(length); + double *d; + rv = d = alloc_d(length); + + int i; for (i = 0; i < length; i++) { - rcheck((dd1[i] >= 0) || (floor(dd2[i]) == ceil(dd2[i])), "power"); + rcheck((dd1[i] >= 0) || (floor(dd2[i]) == ceil(dd2[i])), "power"); d[i] = pow(dd1[i], dd2[i]); } - return ((void *) d); - } else { - c = alloc_c(length); + } + else { + ngcomplex_t *cc1 = (ngcomplex_t *) data1; + ngcomplex_t *cc2 = (ngcomplex_t *) data2; + ngcomplex_t *c, c1, c2, *t; + rv = c = alloc_c(length); + + int i; for (i = 0; i < length; i++) { if (datatype1 == VF_REAL) { realpart(c1) = dd1[i]; imagpart(c1) = 0.0; - } else { + } + else { c1 = cc1[i]; } if (datatype2 == VF_REAL) { realpart(c2) = dd2[i]; imagpart(c2) = 0.0; - } else { + } + else { c2 = cc2[i]; } if ((realpart(c1) == 0.0) && (imagpart(c1) == 0.0)) { realpart(c[i]) = 0.0; imagpart(c[i]) = 0.0; - } else { /* if ((imagpart(c1) != 0.0) && + } + else { /* if ((imagpart(c1) != 0.0) && (imagpart(c2) != 0.0)) */ - t = cexp_sp3(ctimes(&c2, cln(&c1))); + ngcomplex_t tmp, tmp2; + if (cln(&c1, &tmp) != 0) { + (void) fprintf(cp_err, "power of 0 + i 0 not allowed.\n"); + xrc = -1; + goto EXITPOINT; + } + ctimes(&c2, &tmp, &tmp2); + t = cexp_sp3(&tmp2); c[i] = *t; - /* - } else { - realpart(c[i]) = pow(realpart(c1), - realpart(c2)); - imagpart(c[i]) = 0.0; - */ + /* + } else { + realpart(c[i]) = pow(realpart(c1), + realpart(c2)); + imagpart(c[i]) = 0.0; + */ } } - return ((void *) c); } -} + +EXITPOINT: + if (xrc != 0) { /* Free resources on error */ + txfree(rv); + rv = NULL; + } + + return rv; +} /* end of function cx_power */ + + /* These are unnecessary... Only cx_power uses them... */ @@ -175,30 +213,35 @@ cexp_sp3(ngcomplex_t *c) return (&r); } -static ngcomplex_t * -cln(ngcomplex_t *c) +static int cln(ngcomplex_t *c, ngcomplex_t *rv) { - static ngcomplex_t r; + double c_r = c->cx_real; + double c_i = c->cx_imag; - rcheck(cmag(*c) != 0, "ln"); - realpart(r) = log(cmag(*c)); - if (imagpart(*c) != 0.0) - imagpart(r) = atan2(imagpart(*c), realpart(*c)); - else - imagpart(r) = 0.0; - return (&r); -} + if (c_r == 0 && c_i == 0) { + (void) fprintf(cp_err, "Complex log of 0 + i0 is undefined.\n"); + return -1; + } -static ngcomplex_t * -ctimes(ngcomplex_t *c1, ngcomplex_t *c2) + rv->cx_real = log(cmag(*c)); + if (c_i != 0.0) { + rv->cx_imag = atan2(c_i, c_r); + } + else { + rv->cx_imag = 0.0; + } + return 0; +} /* end of functon cln */ + + + +static void ctimes(ngcomplex_t *c1, ngcomplex_t *c2, ngcomplex_t *rv) { - static ngcomplex_t r; - - realpart(r) = realpart(*c1) * realpart(*c2) - + rv->cx_real = realpart(*c1) * realpart(*c2) - imagpart(*c1) * imagpart(*c2); - imagpart(r) = imagpart(*c1) * realpart(*c2) + + rv->cx_imag = imagpart(*c1) * realpart(*c2) + realpart(*c1) * imagpart(*c2); - return (&r); + return; } diff --git a/src/misc/alloc.c b/src/misc/alloc.c index f425d8afc..68e18290c 100644 --- a/src/misc/alloc.c +++ b/src/misc/alloc.c @@ -257,7 +257,7 @@ static inline int product_overflow(size_t a, size_t b, size_t *p_n) * a * b < a * a * b < b */ - if (a == SIZE_MAX && b > 1 || a > 1 && b == SIZE_MAX) { + if ((a == SIZE_MAX && b > 1) || (a > 1 && b == SIZE_MAX)) { return +1; } @@ -283,33 +283,5 @@ static void overflow_error(size_t num, size_t size) } /* end of function overflow_error */ -/* strdup must also be serialized since it performs an allocation. Note that - * Microsoft has not had a single-threaded CRT since VS 2005 (Windows XP), - * so, their _strdup can be safely used if desired. */ -/* Declared in cmproto.h */ -char *tstrdup(const char *str_in) -{ - const size_t n_byte_alloc = strlen(str_in); + 1; - char * const str_out = (char *) tmalloc(n_byte_alloc); - /* Program execution would end in tmalloc() if the allocation fails */ - return memcpy(str_out, str_in, n_byte_alloc); -} /* end of function tstrdup */ - - - -/* Declared in cmproto.h */ -char *tstrdup_raw(const char *str_in) -{ - const size_t n_byte_alloc = strlen(str_in); + 1; - char * const str_out = (char *) tmalloc_raw(n_byte_alloc); - if (str_out == (char *) NULL) { - return (char *) NULL; - } - - return memcpy(str_out, str_in, n_byte_alloc); -} /* end of function tstrdup_raw */ - - - #endif /* #ifndef HAVE_LIBGC */ diff --git a/src/misc/dstring.c b/src/misc/dstring.c index 9833f79b9..d6e22faaf 100644 --- a/src/misc/dstring.c +++ b/src/misc/dstring.c @@ -278,7 +278,7 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg) /* Else check for buffer large enough and set length if it is */ if ((size_t) rc < n_byte_free) { - p_ds->length += rc; + p_ds->length += (size_t) rc; return DS_E_OK; } @@ -286,7 +286,8 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg) { /* Double required size to avoid excessive allocations +1 for * null, which is not included in the count returned by snprintf */ - const size_t n_byte_alloc_min = p_ds->length + rc + 1; + const size_t n_byte_alloc_min = + p_ds->length + (size_t) rc + (size_t) 1; if (ds_reserve_internal(p_ds, 2 * n_byte_alloc_min, n_byte_alloc_min) == DS_E_NO_MEMORY) { /* vsnprintf may have written bytes to the buffer. @@ -308,7 +309,7 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg) /* Else update length. No need to check buffer size since it was * sized to fit the string. */ - p_ds->length += rc2; + p_ds->length += (size_t) rc2; return DS_E_OK; } } /* end of function ds_cat_vprintf */ diff --git a/src/misc/string.c b/src/misc/string.c index 4a5e1ec4e..bf27fb0c3 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -220,9 +220,10 @@ int get_int_n(const char *str, size_t n, int *p_value) if (!isdigit(ch_cur)) { /* Test for exit due to non-numeric char */ break; } - + /* Compute new value and check for overflow. */ - const unsigned int value_new = 10 * value + (ch_cur - '0'); + const unsigned int value_new = + 10 * value + (unsigned int) (ch_cur - '0'); if (value_new < value) { return -2; } @@ -236,7 +237,7 @@ int get_int_n(const char *str, size_t n, int *p_value) /* Test for overflow. * If negative, can be 1 greater (-2**n vs 2**n -1) */ - if (value - f_neg > (unsigned int) INT_MAX) { + if (value - (unsigned int) f_neg > (unsigned int) INT_MAX) { return -2; } @@ -1246,7 +1247,7 @@ static inline const char *next_substr( for ( ; ; ) { /* Update hash for next starting point at p_string + 1 */ if ((h_string = (((h_string - (unsigned char) p_string[0] * - msb_factor) << 8) + p_string[n_char_pattern]) % + msb_factor) << 8) + (size_t) p_string[n_char_pattern]) % KR_MODULUS) > KR_MODULUS) { /* negative value when signed */ h_string += KR_MODULUS; } diff --git a/src/misc/tilde.c b/src/misc/tilde.c index 017330d84..65d2d9987 100644 --- a/src/misc/tilde.c +++ b/src/misc/tilde.c @@ -70,7 +70,7 @@ char *tildexpand(const char *string) string++; } const char * const usr_end = string; - const size_t n_char_usr = usr_end - usr_start; + const size_t n_char_usr = (size_t) (usr_end - usr_start); const size_t n_byte_usr = n_char_usr + 1; if (n_byte_usr > sizeof buf_fixed) { buf = TMALLOC(char, n_byte_usr); diff --git a/src/spicelib/analysis/cktdisto.c b/src/spicelib/analysis/cktdisto.c index 334c15ac9..252554aa2 100644 --- a/src/spicelib/analysis/cktdisto.c +++ b/src/spicelib/analysis/cktdisto.c @@ -27,6 +27,8 @@ CKTdisto (CKTcircuit *ckt, int mode) int error=0; int size; + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch(mode) { case D_SETUP: @@ -63,7 +65,7 @@ CKTdisto (CKTcircuit *ckt, int mode) case D_RHSF1: job->Df2given = 0; /* will change if any F2 source is found */ - + /* FALLTHROUGH */ case D_RHSF2: diff --git a/src/spicelib/devices/asrc/asrcinit.c b/src/spicelib/devices/asrc/asrcinit.c index 4c0797c7d..7455c3784 100644 --- a/src/spicelib/devices/asrc/asrcinit.c +++ b/src/spicelib/devices/asrc/asrcinit.c @@ -34,9 +34,11 @@ SPICEdev ASRCinfo = { .DEVparam = ASRCparam, .DEVmodParam = NULL, .DEVload = ASRCload, - .DEVsetup = ASRCsetup, + .DEVsetup = (int (*)(SMPmatrix *matrix, GENmodel *inModel, + CKTcircuit *ckt, int *states)) ASRCsetup, .DEVunsetup = ASRCunsetup, - .DEVpzSetup = ASRCsetup, + .DEVpzSetup = (int (*)(SMPmatrix *matrix, GENmodel *inModel, + CKTcircuit *ckt, int *states)) ASRCsetup, .DEVtemperature = ASRCtemp, .DEVtrunc = NULL, .DEVfindBranch = ASRCfindBr, diff --git a/src/spicelib/devices/bjt/bjtparam.c b/src/spicelib/devices/bjt/bjtparam.c index 1187dab06..a66e0a8c2 100644 --- a/src/spicelib/devices/bjt/bjtparam.c +++ b/src/spicelib/devices/bjt/bjtparam.c @@ -26,7 +26,7 @@ BJTparam(int param, IFvalue *value, GENinstance *instPtr, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case BJT_AREA: here->BJTarea = value->rValue; here->BJTareaGiven = TRUE; @@ -66,10 +66,13 @@ BJTparam(int param, IFvalue *value, GENinstance *instPtr, IFvalue *select) here->BJTsenParmNo = value->iValue; break; case BJT_IC : - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->BJTicVCE = *(value->v.vec.rVec+1); here->BJTicVCEGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BJTicVBE = *(value->v.vec.rVec); here->BJTicVBEGiven = TRUE; diff --git a/src/spicelib/devices/bsim1/b1par.c b/src/spicelib/devices/bsim1/b1par.c index e097b73e3..0d64b3bcc 100644 --- a/src/spicelib/devices/bsim1/b1par.c +++ b/src/spicelib/devices/bsim1/b1par.c @@ -21,7 +21,7 @@ B1param(int param, IFvalue *value, GENinstance *inst, NG_IGNORE(select); - switch(param) { + switch (param) { case BSIM1_W: here->B1w = value->rValue; here->B1wGiven = TRUE; @@ -74,13 +74,17 @@ B1param(int param, IFvalue *value, GENinstance *inst, here->B1icVGSGiven = TRUE; break; case BSIM1_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue){ case 3: here->B1icVBS = *(value->v.vec.rVec+2); here->B1icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->B1icVGS = *(value->v.vec.rVec+1); here->B1icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->B1icVDS = *(value->v.vec.rVec); here->B1icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim2/b2par.c b/src/spicelib/devices/bsim2/b2par.c index 29e7ed06d..07e62eff1 100644 --- a/src/spicelib/devices/bsim2/b2par.c +++ b/src/spicelib/devices/bsim2/b2par.c @@ -20,7 +20,7 @@ B2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case BSIM2_W: here->B2w = value->rValue; here->B2wGiven = TRUE; @@ -73,13 +73,17 @@ B2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->B2icVGSGiven = TRUE; break; case BSIM2_IC: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch(value->v.numValue){ case 3: here->B2icVBS = *(value->v.vec.rVec+2); here->B2icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->B2icVGS = *(value->v.vec.rVec+1); here->B2icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->B2icVDS = *(value->v.vec.rVec); here->B2icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3/b3par.c b/src/spicelib/devices/bsim3/b3par.c index 35aae2535..ae961b586 100644 --- a/src/spicelib/devices/bsim3/b3par.c +++ b/src/spicelib/devices/bsim3/b3par.c @@ -31,8 +31,8 @@ IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM3_W: + switch (param) { + case BSIM3_W: here->BSIM3w = value->rValue*scale; here->BSIM3wGiven = TRUE; break; @@ -104,13 +104,17 @@ IFvalue *select) here->BSIM3mulu0Given = TRUE; break; case BSIM3_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->BSIM3icVBS = *(value->v.vec.rVec+2); here->BSIM3icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM3icVGS = *(value->v.vec.rVec+1); here->BSIM3icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM3icVDS = *(value->v.vec.rVec); here->BSIM3icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3soi_dd/b3soiddpar.c b/src/spicelib/devices/bsim3soi_dd/b3soiddpar.c index 5749df170..a16ca92ca 100644 --- a/src/spicelib/devices/bsim3soi_dd/b3soiddpar.c +++ b/src/spicelib/devices/bsim3soi_dd/b3soiddpar.c @@ -23,8 +23,10 @@ B3SOIDDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) - { case B3SOIDD_W: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch(param) { + case B3SOIDD_W: here->B3SOIDDw = value->rValue; here->B3SOIDDwGiven = TRUE; break; @@ -104,19 +106,23 @@ B3SOIDDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->B3SOIDDbodySquaresGiven = TRUE; break; case B3SOIDD_IC: - switch(value->v.numValue){ + switch (value->v.numValue) { case 5: here->B3SOIDDicVPS = *(value->v.vec.rVec+4); here->B3SOIDDicVPSGiven = TRUE; + /* FALLTHROUGH */ case 4: here->B3SOIDDicVES = *(value->v.vec.rVec+3); here->B3SOIDDicVESGiven = TRUE; + /* FALLTHROUGH */ case 3: here->B3SOIDDicVBS = *(value->v.vec.rVec+2); here->B3SOIDDicVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->B3SOIDDicVGS = *(value->v.vec.rVec+1); here->B3SOIDDicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->B3SOIDDicVDS = *(value->v.vec.rVec); here->B3SOIDDicVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3soi_fd/b3soifdpar.c b/src/spicelib/devices/bsim3soi_fd/b3soifdpar.c index a1351b946..db2d2b32a 100644 --- a/src/spicelib/devices/bsim3soi_fd/b3soifdpar.c +++ b/src/spicelib/devices/bsim3soi_fd/b3soifdpar.c @@ -24,8 +24,8 @@ B3SOIFDparam(int param, IFvalue *value, GENinstance *inst, NG_IGNORE(select); - switch(param) - { case B3SOIFD_W: + switch (param) { + case B3SOIFD_W: here->B3SOIFDw = value->rValue; here->B3SOIFDwGiven = TRUE; break; @@ -105,19 +105,25 @@ B3SOIFDparam(int param, IFvalue *value, GENinstance *inst, here->B3SOIFDbodySquaresGiven = TRUE; break; case B3SOIFD_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 5: here->B3SOIFDicVPS = *(value->v.vec.rVec+4); here->B3SOIFDicVPSGiven = TRUE; + /* FALLTHROUGH */ case 4: here->B3SOIFDicVES = *(value->v.vec.rVec+3); here->B3SOIFDicVESGiven = TRUE; + /* FALLTHROUGH */ case 3: here->B3SOIFDicVBS = *(value->v.vec.rVec+2); here->B3SOIFDicVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->B3SOIFDicVGS = *(value->v.vec.rVec+1); here->B3SOIFDicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->B3SOIFDicVDS = *(value->v.vec.rVec); here->B3SOIFDicVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3soi_pd/b3soipdpar.c b/src/spicelib/devices/bsim3soi_pd/b3soipdpar.c index 84cdc6df5..624e41009 100644 --- a/src/spicelib/devices/bsim3soi_pd/b3soipdpar.c +++ b/src/spicelib/devices/bsim3soi_pd/b3soipdpar.c @@ -25,8 +25,10 @@ B3SOIPDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) - { case B3SOIPD_W: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch(param) { + case B3SOIPD_W: here->B3SOIPDw = value->rValue; here->B3SOIPDwGiven = TRUE; break; @@ -148,19 +150,23 @@ B3SOIPDparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) case B3SOIPD_IC: - switch(value->v.numValue){ + switch (value->v.numValue) { case 5: here->B3SOIPDicVPS = *(value->v.vec.rVec+4); here->B3SOIPDicVPSGiven = TRUE; + /* FALLTHROUGH */ case 4: here->B3SOIPDicVES = *(value->v.vec.rVec+3); here->B3SOIPDicVESGiven = TRUE; + /* FALLTHROUGH */ case 3: here->B3SOIPDicVBS = *(value->v.vec.rVec+2); here->B3SOIPDicVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->B3SOIPDicVGS = *(value->v.vec.rVec+1); here->B3SOIPDicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->B3SOIPDicVDS = *(value->v.vec.rVec); here->B3SOIPDicVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3v0/b3v0par.c b/src/spicelib/devices/bsim3v0/b3v0par.c index 8fe314af7..c3d0ac1c3 100644 --- a/src/spicelib/devices/bsim3v0/b3v0par.c +++ b/src/spicelib/devices/bsim3v0/b3v0par.c @@ -23,8 +23,8 @@ BSIM3v0param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM3v0_W: + switch (param) { + case BSIM3v0_W: here->BSIM3v0w = value->rValue*scale; here->BSIM3v0wGiven = TRUE; break; @@ -80,13 +80,17 @@ BSIM3v0param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->BSIM3v0nqsModGiven = TRUE; break; case BSIM3v0_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->BSIM3v0icVBS = *(value->v.vec.rVec+2); here->BSIM3v0icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM3v0icVGS = *(value->v.vec.rVec+1); here->BSIM3v0icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM3v0icVDS = *(value->v.vec.rVec); here->BSIM3v0icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3v1/b3v1par.c b/src/spicelib/devices/bsim3v1/b3v1par.c index 2c58743ef..839b604c1 100644 --- a/src/spicelib/devices/bsim3v1/b3v1par.c +++ b/src/spicelib/devices/bsim3v1/b3v1par.c @@ -29,8 +29,8 @@ BSIM3v1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM3v1_W: + switch (param) { + case BSIM3v1_W: here->BSIM3v1w = value->rValue*scale; here->BSIM3v1wGiven = TRUE; break; @@ -86,13 +86,17 @@ BSIM3v1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->BSIM3v1nqsModGiven = TRUE; break; case BSIM3v1_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->BSIM3v1icVBS = *(value->v.vec.rVec+2); here->BSIM3v1icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM3v1icVGS = *(value->v.vec.rVec+1); here->BSIM3v1icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM3v1icVDS = *(value->v.vec.rVec); here->BSIM3v1icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim3v32/b3v32par.c b/src/spicelib/devices/bsim3v32/b3v32par.c index 83f1b4a61..ff5d7fa82 100644 --- a/src/spicelib/devices/bsim3v32/b3v32par.c +++ b/src/spicelib/devices/bsim3v32/b3v32par.c @@ -28,8 +28,8 @@ BSIM3v32param (int param, IFvalue *value, GENinstance *inst, IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM3v32_W: + switch (param) { + case BSIM3v32_W: here->BSIM3v32w = value->rValue*scale; here->BSIM3v32wGiven = TRUE; break; @@ -97,13 +97,17 @@ BSIM3v32param (int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->BSIM3v32mulu0Given = TRUE; break; case BSIM3v32_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->BSIM3v32icVBS = *(value->v.vec.rVec+2); here->BSIM3v32icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM3v32icVGS = *(value->v.vec.rVec+1); here->BSIM3v32icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM3v32icVDS = *(value->v.vec.rVec); here->BSIM3v32icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim4/b4par.c b/src/spicelib/devices/bsim4/b4par.c index 702e81c7b..b57337d23 100644 --- a/src/spicelib/devices/bsim4/b4par.c +++ b/src/spicelib/devices/bsim4/b4par.c @@ -81,8 +81,8 @@ IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM4_W: + switch (param) { + case BSIM4_W: here->BSIM4w = value->rValue * scale; here->BSIM4wGiven = TRUE; break; @@ -230,13 +230,17 @@ IFvalue *select) here->BSIM4icVBSGiven = TRUE; break; case BSIM4_IC: - switch(value->v.numValue) - { case 3: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { + case 3: here->BSIM4icVBS = *(value->v.vec.rVec+2); here->BSIM4icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM4icVGS = *(value->v.vec.rVec+1); here->BSIM4icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM4icVDS = *(value->v.vec.rVec); here->BSIM4icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim4v5/b4v5par.c b/src/spicelib/devices/bsim4v5/b4v5par.c index a75f7217e..e62b7f660 100644 --- a/src/spicelib/devices/bsim4v5/b4v5par.c +++ b/src/spicelib/devices/bsim4v5/b4v5par.c @@ -35,8 +35,8 @@ IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM4v5_W: + switch (param) { + case BSIM4v5_W: here->BSIM4v5w = value->rValue*scale; here->BSIM4v5wGiven = TRUE; break; @@ -180,13 +180,17 @@ IFvalue *select) here->BSIM4v5icVBSGiven = TRUE; break; case BSIM4v5_IC: - switch(value->v.numValue) - { case 3: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { + case 3: here->BSIM4v5icVBS = *(value->v.vec.rVec+2); here->BSIM4v5icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM4v5icVGS = *(value->v.vec.rVec+1); here->BSIM4v5icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM4v5icVDS = *(value->v.vec.rVec); here->BSIM4v5icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim4v6/b4v6par.c b/src/spicelib/devices/bsim4v6/b4v6par.c index a3ff5023d..87e0bc09e 100644 --- a/src/spicelib/devices/bsim4v6/b4v6par.c +++ b/src/spicelib/devices/bsim4v6/b4v6par.c @@ -37,8 +37,8 @@ IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM4v6_W: + switch (param) { + case BSIM4v6_W: here->BSIM4v6w = value->rValue*scale; here->BSIM4v6wGiven = TRUE; break; @@ -182,13 +182,17 @@ IFvalue *select) here->BSIM4v6icVBSGiven = TRUE; break; case BSIM4v6_IC: - switch(value->v.numValue) - { case 3: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { + case 3: here->BSIM4v6icVBS = *(value->v.vec.rVec+2); here->BSIM4v6icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM4v6icVGS = *(value->v.vec.rVec+1); here->BSIM4v6icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM4v6icVDS = *(value->v.vec.rVec); here->BSIM4v6icVDSGiven = TRUE; diff --git a/src/spicelib/devices/bsim4v7/b4v7par.c b/src/spicelib/devices/bsim4v7/b4v7par.c index f152f8df6..5e42f1596 100644 --- a/src/spicelib/devices/bsim4v7/b4v7par.c +++ b/src/spicelib/devices/bsim4v7/b4v7par.c @@ -37,8 +37,8 @@ IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) - { case BSIM4v7_W: + switch (param) { + case BSIM4v7_W: here->BSIM4v7w = value->rValue * scale; here->BSIM4v7wGiven = TRUE; break; @@ -186,13 +186,17 @@ IFvalue *select) here->BSIM4v7icVBSGiven = TRUE; break; case BSIM4v7_IC: - switch(value->v.numValue) - { case 3: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { + case 3: here->BSIM4v7icVBS = *(value->v.vec.rVec+2); here->BSIM4v7icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->BSIM4v7icVGS = *(value->v.vec.rVec+1); here->BSIM4v7icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->BSIM4v7icVDS = *(value->v.vec.rVec); here->BSIM4v7icVDSGiven = TRUE; diff --git a/src/spicelib/devices/cpl/cplload.c b/src/spicelib/devices/cpl/cplload.c index 9a8e06ba9..3f5aef254 100644 --- a/src/spicelib/devices/cpl/cplload.c +++ b/src/spicelib/devices/cpl/cplload.c @@ -789,45 +789,44 @@ errordetect: } -static int -update_delayed_cnv(CPLine *cp, double h) +static int update_delayed_cnv(CPLine *cp, double h) { int i, j, k; - double *ratio; + double *ratio1; double f; VI_list *vi; TMS *tms; int noL; h *= 0.5e-12; - ratio = cp->ratio; + ratio1 = cp->ratio; vi = cp->vi_tail; noL = cp->noL; for (k = 0; k < noL; k++) /* mode */ - if (ratio[k] > 0.0) + if (ratio1[k] > 0.0) for (i = 0; i < noL; i++) /* current eqn */ for (j = 0; j < noL; j++) { tms = cp->h3t[i][j][k]; if (tms == NULL) continue; - f = h * ratio[k] * vi->v_i[j]; + f = h * ratio1[k] * vi->v_i[j]; tms->tm[0].cnv_i += f * tms->tm[0].c; tms->tm[1].cnv_i += f * tms->tm[1].c; tms->tm[2].cnv_i += f * tms->tm[2].c; - f = h * ratio[k] * vi->v_o[j]; + f = h * ratio1[k] * vi->v_o[j]; tms->tm[0].cnv_o += f * tms->tm[0].c; tms->tm[1].cnv_o += f * tms->tm[1].c; tms->tm[2].cnv_o += f * tms->tm[2].c; tms = cp->h2t[i][j][k]; - f = h * ratio[k] * vi->i_i[j]; + f = h * ratio1[k] * vi->i_i[j]; tms->tm[0].cnv_i += f * tms->tm[0].c; tms->tm[1].cnv_i += f * tms->tm[1].c; tms->tm[2].cnv_i += f * tms->tm[2].c; - f = h * ratio[k] * vi->i_o[j]; + f = h * ratio1[k] * vi->i_o[j]; tms->tm[0].cnv_o += f * tms->tm[0].c; tms->tm[1].cnv_o += f * tms->tm[1].c; tms->tm[2].cnv_o += f * tms->tm[2].c; diff --git a/src/spicelib/devices/cpl/cplsetup.c b/src/spicelib/devices/cpl/cplsetup.c index cff29580a..3913e6d83 100644 --- a/src/spicelib/devices/cpl/cplsetup.c +++ b/src/spicelib/devices/cpl/cplsetup.c @@ -1061,14 +1061,14 @@ loop_ZY(int dim, double y) static void poly_matrix( - double *A[MAX_DIM][MAX_DIM], + double *A_in[MAX_DIM][MAX_DIM], int dim, int deg) { int i, j; for (i = 0; i < dim; i++) for (j = 0; j < dim; j++) - match(deg, A[i][j], frequency, A[i][j]); + match(deg, A_in[i][j], frequency, A_in[i][j]); } /*** @@ -1464,10 +1464,9 @@ mult_p(double *p1, double *p2, double *p3, int d1, int d2, int d3) } -static void -matrix_p_mult( - double *A[MAX_DIM][MAX_DIM], - double *D[MAX_DIM], +static void matrix_p_mult( + double *A_in[MAX_DIM][MAX_DIM], + double *D1[MAX_DIM], double *B[MAX_DIM][MAX_DIM], int dim, int deg, int deg_o, Mult_Out X[MAX_DIM][MAX_DIM]) @@ -1480,14 +1479,14 @@ matrix_p_mult( for (i = 0; i < dim; i++) for (j = 0; j < dim; j++) { p = T[i][j] = (double *) calloc((size_t) (deg_o+1), sizeof(double)); - mult_p(B[i][j], D[i], p, deg, deg_o, deg_o); + mult_p(B[i][j], D1[i], p, deg, deg_o, deg_o); } for (i = 0; i < dim; i++) for (j = 0; j < dim; j++) for (k = 0; k < dim; k++) { p = X[i][j].Poly[k] = (double *) calloc((size_t) (deg_o+1), sizeof(double)); - mult_p(A[i][k], T[k][j], p, deg, deg_o, deg_o); + mult_p(A_in[i][k], T[k][j], p, deg, deg_o, deg_o); t1 = X[i][j].C_0[k] = p[0]; if (t1 != 0.0) { p[0] = 1.0; @@ -1523,7 +1522,7 @@ matrix_p_mult( ***/ static double -approx_mode(double *X, double *b, double length) +approx_mode(double *X, double *b, double length_in) { double w0, w1, w2, w3, w4, w5; double a[8]; @@ -1545,7 +1544,7 @@ approx_mode(double *X, double *b, double length) y5 = 60.0 * w5 - 5.0 * y1 * y4 -10.0 * y2 * y3; y6 = -10.0 * y3 * y3 - 15.0 * y2 * y4 - 6.0 * y1 * y5; - delay = sqrt(w0) * length / Scaling_F; + delay = sqrt(w0) * length_in / Scaling_F; atten = exp(- delay * y1); a[1] = y2 / 2.0; @@ -2080,8 +2079,7 @@ diag(int dims) rotate() rotation of the Jacobi's method ****************************************************************/ -static int -rotate(int dim, int p, int q) +static int rotate(int dim_in, int p, int q) { int j; double co, si; @@ -2095,12 +2093,12 @@ rotate(int dim, int p, int q) co = sqrt((ve + ABS(mu)) / (2.0 * ve)); si = SGN(mu) * ld / (2.0 * ve * co); - for (j = p+1; j < dim; j++) + for (j = p+1; j < dim_in; j++) T[j] = ZY[p][j]; for (j = 0; j < p; j++) T[j] = ZY[j][p]; - for (j = p+1; j < dim; j++) { + for (j = p+1; j < dim_in; j++) { if (j == q) continue; if (j > q) @@ -2108,7 +2106,7 @@ rotate(int dim, int p, int q) else ZY[p][j] = T[j] * co - ZY[j][q] * si; } - for (j = q+1; j < dim; j++) { + for (j = q+1; j < dim_in; j++) { if (j == p) continue; ZY[q][j] = T[j] * si + ZY[q][j] * co; @@ -2133,12 +2131,12 @@ rotate(int dim, int p, int q) { double R[MAX_DIM]; - for (j = 0; j < dim; j++) { + for (j = 0; j < dim_in; j++) { T[j] = Sv[j][p]; R[j] = Sv[j][q]; } - for (j = 0; j < dim; j++) { + for (j = 0; j < dim_in; j++) { Sv[j][p] = T[j] * co - R[j] * si; Sv[j][q] = T[j] * si + R[j] * co; } diff --git a/src/spicelib/devices/dev.c b/src/spicelib/devices/dev.c index baac72e44..535c8e68e 100644 --- a/src/spicelib/devices/dev.c +++ b/src/spicelib/devices/dev.c @@ -479,15 +479,11 @@ int load_opus(const char *name) #endif - /* Give the code model access to facilities provided by ngspice. Note - * that older versions of code models will not access the functions - * added by newer versions of ngspice since it is unaware of them and - * newer versions of code models will not use newer (undefined) - * functions from ngspice because any of its models that use them - * will not be recognized and used by ngspice. */ + /* Give the code model access to facilities provided by ngspice. */ if ((fetch = dlsym(lib,"CMgetCoreItfPtr")) != (funptr_t) NULL) { const struct coreInfo_t ** const core = - (*(const struct coreInfo_t ** const (*)(void)) fetch)(); + (const struct coreInfo_t **const) + (*(struct coreInfo_t ** (*)(void)) fetch)(); *core = &coreInfo; } else { diff --git a/src/spicelib/devices/hfet1/hfetparam.c b/src/spicelib/devices/hfet1/hfetparam.c index 766fba189..959964e48 100644 --- a/src/spicelib/devices/hfet1/hfetparam.c +++ b/src/spicelib/devices/hfet1/hfetparam.c @@ -18,7 +18,7 @@ HFETAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case HFETA_LENGTH: here->HFETAlength = value->rValue; here->HFETAlengthGiven = TRUE; @@ -43,10 +43,13 @@ HFETAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->HFETAoff = value->iValue; break; case HFETA_IC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->HFETAicVGS = *(value->v.vec.rVec+1); here->HFETAicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->HFETAicVDS = *(value->v.vec.rVec); here->HFETAicVDSGiven = TRUE; diff --git a/src/spicelib/devices/hfet2/hfet2param.c b/src/spicelib/devices/hfet2/hfet2param.c index b43eb0738..3ceab0547 100644 --- a/src/spicelib/devices/hfet2/hfet2param.c +++ b/src/spicelib/devices/hfet2/hfet2param.c @@ -16,8 +16,8 @@ int HFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) HFET2instance *here = (HFET2instance*)inst; NG_IGNORE(select); - - switch(param) { + + switch (param) { case HFET2_LENGTH: L = value->rValue; here->HFET2lengthGiven = TRUE; @@ -34,10 +34,13 @@ int HFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->HFET2off = value->iValue; break; case HFET2_IC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->HFET2icVGS = *(value->v.vec.rVec+1); here->HFET2icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->HFET2icVDS = *(value->v.vec.rVec); here->HFET2icVDSGiven = TRUE; diff --git a/src/spicelib/devices/hisim2/hsm2par.c b/src/spicelib/devices/hisim2/hsm2par.c index 6e84d115d..62ae8cbee 100644 --- a/src/spicelib/devices/hisim2/hsm2par.c +++ b/src/spicelib/devices/hisim2/hsm2par.c @@ -133,13 +133,17 @@ int HSM2param( here->HSM2_icVGS_Given = TRUE; break; case HSM2_IC: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch (value->v.numValue) { case 3: here->HSM2_icVBS = *(value->v.vec.rVec + 2); here->HSM2_icVBS_Given = TRUE; + /* FALLTHROUGH */ case 2: here->HSM2_icVGS = *(value->v.vec.rVec + 1); here->HSM2_icVGS_Given = TRUE; + /* FALLTHROUGH */ case 1: here->HSM2_icVDS = *(value->v.vec.rVec); here->HSM2_icVDS_Given = TRUE; diff --git a/src/spicelib/devices/hisimhv1/hsmhvpar.c b/src/spicelib/devices/hisimhv1/hsmhvpar.c index 3ace52ccc..6571c02e4 100644 --- a/src/spicelib/devices/hisimhv1/hsmhvpar.c +++ b/src/spicelib/devices/hisimhv1/hsmhvpar.c @@ -102,9 +102,11 @@ int HSMHVparam( case 3: here->HSMHV_icVBS = *(value->v.vec.rVec + 2); here->HSMHV_icVBS_Given = TRUE; + /* FALLTHROUGH */ case 2: here->HSMHV_icVGS = *(value->v.vec.rVec + 1); here->HSMHV_icVGS_Given = TRUE; + /* FALLTHROUGH */ case 1: here->HSMHV_icVDS = *(value->v.vec.rVec); here->HSMHV_icVDS_Given = TRUE; diff --git a/src/spicelib/devices/hisimhv2/hsmhv2par.c b/src/spicelib/devices/hisimhv2/hsmhv2par.c index be803e1e5..999426f29 100644 --- a/src/spicelib/devices/hisimhv2/hsmhv2par.c +++ b/src/spicelib/devices/hisimhv2/hsmhv2par.c @@ -140,13 +140,17 @@ int HSMHV2param( here->HSMHV2_icVGS_Given = TRUE; break; case HSMHV2_IC: + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch (value->v.numValue) { case 3: here->HSMHV2_icVBS = *(value->v.vec.rVec + 2); here->HSMHV2_icVBS_Given = TRUE; + /* FALLTHROUGH */ case 2: here->HSMHV2_icVGS = *(value->v.vec.rVec + 1); here->HSMHV2_icVGS_Given = TRUE; + /* FALLTHROUGH */ case 1: here->HSMHV2_icVDS = *(value->v.vec.rVec); here->HSMHV2_icVDS_Given = TRUE; diff --git a/src/spicelib/devices/isrc/isrcpar.c b/src/spicelib/devices/isrc/isrcpar.c index cecf2e199..f66b3bd03 100644 --- a/src/spicelib/devices/isrc/isrcpar.c +++ b/src/spicelib/devices/isrc/isrcpar.c @@ -38,7 +38,7 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case ISRC_DC: here->ISRCdcValue = value->rValue; @@ -63,13 +63,17 @@ ISRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) break; case ISRC_AC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->ISRCacPhase = *(value->v.vec.rVec+1); here->ISRCacPGiven = TRUE; + /* FALLTHROUGH */ case 1: here->ISRCacMag = *(value->v.vec.rVec); here->ISRCacMGiven = TRUE; + /* FALLTHROUGH */ case 0: here->ISRCacGiven = TRUE; break; diff --git a/src/spicelib/devices/jfet/jfetpar.c b/src/spicelib/devices/jfet/jfetpar.c index a45d5cc61..64dae9f3d 100644 --- a/src/spicelib/devices/jfet/jfetpar.c +++ b/src/spicelib/devices/jfet/jfetpar.c @@ -21,7 +21,7 @@ JFETparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case JFET_TEMP: here->JFETtemp = value->rValue+CONSTCtoK; here->JFETtempGiven = TRUE; @@ -50,10 +50,13 @@ JFETparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->JFEToff = (value->iValue != 0); break; case JFET_IC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->JFETicVGS = *(value->v.vec.rVec+1); here->JFETicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->JFETicVDS = *(value->v.vec.rVec); here->JFETicVDSGiven = TRUE; diff --git a/src/spicelib/devices/jfet2/jfet2par.c b/src/spicelib/devices/jfet2/jfet2par.c index 84acdfe07..44c6b9fc3 100644 --- a/src/spicelib/devices/jfet2/jfet2par.c +++ b/src/spicelib/devices/jfet2/jfet2par.c @@ -25,7 +25,7 @@ JFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case JFET2_TEMP: here->JFET2temp = value->rValue+CONSTCtoK; here->JFET2tempGiven = TRUE; @@ -54,10 +54,13 @@ JFET2param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->JFET2off = (value->iValue != 0); break; case JFET2_IC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->JFET2icVGS = *(value->v.vec.rVec+1); here->JFET2icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->JFET2icVDS = *(value->v.vec.rVec); here->JFET2icVDSGiven = TRUE; diff --git a/src/spicelib/devices/ltra/ltraload.c b/src/spicelib/devices/ltra/ltraload.c index 1a0c143c2..01e631b23 100644 --- a/src/spicelib/devices/ltra/ltraload.c +++ b/src/spicelib/devices/ltra/ltraload.c @@ -90,6 +90,8 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt) break; } + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch (model->LTRAspecialCase) { case LTRA_MOD_RLC: /* @@ -122,6 +124,7 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt) model->LTRAtd, model->LTRAalpha, model->LTRAbeta, ckt->CKTtime, ckt->CKTtimePoints, ckt->CKTtimeIndex, model->LTRAchopReltol, &(model->LTRAauxIndex)); + /* FALLTHROUGH */ case LTRA_MOD_LC: @@ -308,6 +311,7 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt) *(here->LTRAibr2Pos2Ptr) += dummy1; *(here->LTRAibr2Neg2Ptr) -= dummy1; /* end loading for convolution parts' first terms */ + /* FALLTHROUGH */ case LTRA_MOD_LC: /* @@ -591,6 +595,8 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt) return (E_BADPARM); } + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch (model->LTRAspecialCase) { case LTRA_MOD_RLC: @@ -701,6 +707,7 @@ LTRAload(GENmodel *inModel, CKTcircuit *ckt) /* end convolution of h3dash with v2 and v1 */ + /* FALLTHROUGH */ case LTRA_MOD_LC: /* begin lossless-like parts */ diff --git a/src/spicelib/devices/ltra/ltrapar.c b/src/spicelib/devices/ltra/ltrapar.c index fea03737f..78b2b0155 100644 --- a/src/spicelib/devices/ltra/ltrapar.c +++ b/src/spicelib/devices/ltra/ltrapar.c @@ -39,10 +39,13 @@ LTRAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) switch (value->v.numValue) { case 4: here->LTRAinitCur2 = *(value->v.vec.rVec + 3); + /* FALLTHROUGH */ case 3: here->LTRAinitVolt2 = *(value->v.vec.rVec + 2); + /* FALLTHROUGH */ case 2: here->LTRAinitCur1 = *(value->v.vec.rVec + 1); + /* FALLTHROUGH */ case 1: here->LTRAinitVolt1 = *(value->v.vec.rVec); break; diff --git a/src/spicelib/devices/mes/mesparam.c b/src/spicelib/devices/mes/mesparam.c index ce635757a..d6bd06a6c 100644 --- a/src/spicelib/devices/mes/mesparam.c +++ b/src/spicelib/devices/mes/mesparam.c @@ -20,7 +20,7 @@ MESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case MES_AREA: here->MESarea = value->rValue; here->MESareaGiven = TRUE; @@ -41,10 +41,13 @@ MESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->MESoff = value->iValue; break; case MES_IC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->MESicVGS = *(value->v.vec.rVec+1); here->MESicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MESicVDS = *(value->v.vec.rVec); here->MESicVDSGiven = TRUE; diff --git a/src/spicelib/devices/mesa/mesaparam.c b/src/spicelib/devices/mesa/mesaparam.c index 5399eef71..98ab7f138 100644 --- a/src/spicelib/devices/mesa/mesaparam.c +++ b/src/spicelib/devices/mesa/mesaparam.c @@ -19,7 +19,7 @@ MESAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case MESA_LENGTH: here->MESAlength = value->rValue; here->MESAlengthGiven = TRUE; @@ -45,10 +45,13 @@ MESAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->MESAoff = value->iValue; break; case MESA_IC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->MESAicVGS = *(value->v.vec.rVec+1); here->MESAicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MESAicVDS = *(value->v.vec.rVec); here->MESAicVDSGiven = TRUE; diff --git a/src/spicelib/devices/mos1/mos1par.c b/src/spicelib/devices/mos1/mos1par.c index 3ae4681fd..07c3a5ddd 100644 --- a/src/spicelib/devices/mos1/mos1par.c +++ b/src/spicelib/devices/mos1/mos1par.c @@ -28,7 +28,7 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) { + switch (param) { case MOS1_TEMP: here->MOS1temp = value->rValue+CONSTCtoK; here->MOS1tempGiven = TRUE; @@ -89,13 +89,17 @@ MOS1param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->MOS1icVGSGiven = TRUE; break; case MOS1_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->MOS1icVBS = *(value->v.vec.rVec+2); here->MOS1icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->MOS1icVGS = *(value->v.vec.rVec+1); here->MOS1icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MOS1icVDS = *(value->v.vec.rVec); here->MOS1icVDSGiven = TRUE; diff --git a/src/spicelib/devices/mos2/mos2dset.c b/src/spicelib/devices/mos2/mos2dset.c index 600fa354a..a6459b63a 100644 --- a/src/spicelib/devices/mos2/mos2dset.c +++ b/src/spicelib/devices/mos2/mos2dset.c @@ -193,8 +193,8 @@ MOS2dSetup(GENmodel *inModel, CKTcircuit *ckt) * this routine evaluates the drain current, its derivatives and * the charges associated with the gate, channel and bulk * for mosfets * */ - double arg; - double sarg; + double arg1; + double sarg1; double a4[4],b4[4],x4[8],poly4[8]; double beta1; double sphi = 0.0; /* square root of phi */ @@ -358,22 +358,22 @@ d_p.d3_pqr = 0.0; d_phiMinVbs.d1_q = - d_phiMinVbs.d1_q; if (lvbs <= 0.0) { - sarg = sqrt(phiMinVbs); + sarg1 = sqrt(phiMinVbs); SqrtDeriv(&d_sarg, &d_phiMinVbs); - dsrgdb = -0.5/sarg; + dsrgdb = -0.5/sarg1; InvDeriv(&d_dsrgdb,&d_sarg); TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5); } else { sphi = sqrt(here->MOS2tPhi); /*const*/ sphi3 = here->MOS2tPhi*sphi; /*const*/ - sarg = sphi/(1.0+0.5*lvbs/here->MOS2tPhi); + sarg1 = sphi/(1.0+0.5*lvbs/here->MOS2tPhi); EqualDeriv(&d_sarg,&d_q); d_sarg.value = lvbs; TimesDeriv(&d_sarg,&d_sarg,0.5/here->MOS2tPhi); d_sarg.value += 1.0; InvDeriv(&d_sarg,&d_sarg); TimesDeriv(&d_sarg,&d_sarg,sphi); - dsrgdb = -0.5*sarg*sarg/sphi3; + dsrgdb = -0.5*sarg1*sarg1/sphi3; MultDeriv(&d_dsrgdb,&d_sarg,&d_sarg); TimesDeriv(&d_dsrgdb,&d_dsrgdb,-0.5/sphi3); /* tmp = sarg/sphi3; */ @@ -422,7 +422,7 @@ d_p.d3_pqr = 0.0; if ((model->MOS2gamma > 0.0) || (model->MOS2substrateDoping > 0.0)) { xwd = model->MOS2xd*barg; - xws = model->MOS2xd*sarg; + xws = model->MOS2xd*sarg1; TimesDeriv(&d_xwd,&d_barg,model->MOS2xd); TimesDeriv(&d_xws,&d_sarg,model->MOS2xd); @@ -484,7 +484,7 @@ d_p.d3_pqr = 0.0; dgddvb = 0.0; EqualDeriv(&d_dgddvb,&d_zero); } - von = vbin+gamasd*sarg; + von = vbin+gamasd*sarg1; MultDeriv(&d_von,&d_gamasd,&d_sarg); PlusDeriv(&d_von,&d_von,&d_vbin); /* @@ -497,7 +497,7 @@ d_p.d3_pqr = 0.0; /* XXX constant per model */ cfs = CHARGE*model->MOS2fastSurfaceStateDensity* 1e4 /*(cm**2/m**2)*/; - cdonco = -(gamasd*dsrgdb + dgddvb*sarg) + factor; + cdonco = -(gamasd*dsrgdb + dgddvb*sarg1) + factor; MultDeriv(&d_dummy,&d_dgddvb,&d_sarg); MultDeriv(&d_cdonco,&d_gamasd,&d_dsrgdb); PlusDeriv(&d_cdonco,&d_cdonco,&d_dummy); @@ -533,7 +533,7 @@ d_p.d3_pqr = 0.0; /* * compute some more useful quantities */ - sarg3 = sarg*sarg*sarg; + sarg3 = sarg1*sarg1*sarg1; CubeDeriv(&d_sarg3,&d_sarg); /* XXX constant per model */ sbiarg = sqrt(here->MOS2tBulkPot); /*const*/ @@ -599,7 +599,7 @@ line500: vdsat = 0.0; EqualDeriv(&d_vdsat,&d_zero); } else { - arg = sqrt(1.0+4.0*argv/gammd2); + arg1 = sqrt(1.0+4.0*argv/gammd2); DivDeriv(&d_arg,&d_argv,&d_gammd2); TimesDeriv(&d_arg,&d_arg,4.0);d_arg.value += 1.0; SqrtDeriv(&d_arg,&d_arg); @@ -883,14 +883,14 @@ line500: MultDeriv(&d_sargv,&d_argv,&d_argv); d_sargv.value += 1.0; SqrtDeriv(&d_sargv,&d_sargv); - arg = sqrt(argv+sargv); + arg1 = sqrt(argv+sargv); PlusDeriv(&d_arg,&d_sargv,&d_argv); SqrtDeriv(&d_arg,&d_arg); xlfact = model->MOS2xd/(EffectiveLength*lvds); EqualDeriv(&d_xlfact,&d_r); d_xlfact.value = lvds; InvDeriv(&d_xlfact,&d_xlfact); TimesDeriv(&d_xlfact,&d_xlfact,model->MOS2xd/EffectiveLength); - xlamda = xlfact*arg; + xlamda = xlfact*arg1; MultDeriv(&d_xlamda,&d_xlfact,&d_arg); } else { argv = (vgsx-vbin)/eta-vdsat; @@ -990,7 +990,7 @@ line610: goto line1050; } - here->MOS2gds = beta1*(von-vbin-gammad*sarg)*exp(argg* + here->MOS2gds = beta1*(von-vbin-gammad*sarg1)*exp(argg* (lvgs-von)); MultDeriv(&d_dummy,&d_gammad,&d_sarg); PlusDeriv(&d_dummy,&d_dummy,&d_vbin); @@ -1011,7 +1011,7 @@ line610: } - here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg); + here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg1); MultDeriv(&d_mos2gds,&d_gammad,&d_sarg); PlusDeriv(&d_mos2gds,&d_mos2gds,&d_vbin); TimesDeriv(&d_mos2gds,&d_mos2gds,-1.0); diff --git a/src/spicelib/devices/mos2/mos2load.c b/src/spicelib/devices/mos2/mos2load.c index e5b1ee724..161a1641a 100644 --- a/src/spicelib/devices/mos2/mos2load.c +++ b/src/spicelib/devices/mos2/mos2load.c @@ -431,8 +431,8 @@ next1: if(vbs <= -3*vt) { * */ - double arg; - double sarg; + double arg1; + double sarg1; double a4[4],b4[4],x4[8],poly4[8]; double beta1; double dsrgdb; @@ -569,15 +569,15 @@ next1: if(vbs <= -3*vt) { */ if (lvbs <= 0.0) { - sarg = sqrt(phiMinVbs); - dsrgdb = -0.5/sarg; + sarg1 = sqrt(phiMinVbs); + dsrgdb = -0.5/sarg1; d2sdb2 = 0.5*dsrgdb/phiMinVbs; } else { sphi = sqrt(here->MOS2tPhi); sphi3 = here->MOS2tPhi*sphi; - sarg = sphi/(1.0+0.5*lvbs/here->MOS2tPhi); - tmp = sarg/sphi3; - dsrgdb = -0.5*sarg*tmp; + sarg1 = sphi/(1.0+0.5*lvbs/here->MOS2tPhi); + tmp = sarg1/sphi3; + dsrgdb = -0.5*sarg1*tmp; d2sdb2 = -dsrgdb*tmp; } if ((lvbs-lvds) <= 0) { @@ -606,7 +606,7 @@ next1: if(vbs <= -3*vt) { if ((model->MOS2gamma > 0.0) || (model->MOS2substrateDoping > 0.0)) { xwd = model->MOS2xd*barg; - xws = model->MOS2xd*sarg; + xws = model->MOS2xd*sarg1; /* * short-channel effect with vds .ne. 0.0 @@ -655,14 +655,14 @@ next1: if(vbs <= -3*vt) { dgdvds = 0.0; dgddb2 = 0.0; } - von = vbin+gamasd*sarg; + von = vbin+gamasd*sarg1; vth = von; vdsat = 0.0; if (model->MOS2fastSurfaceStateDensity != 0.0 && OxideCap != 0.0) { /* XXX constant per model */ cfs = CHARGE*model->MOS2fastSurfaceStateDensity* 1e4 /*(cm**2/m**2)*/; - cdonco = -(gamasd*dsrgdb+dgddvb*sarg)+factor; + cdonco = -(gamasd*dsrgdb+dgddvb*sarg1)+factor; xn = 1.0+cfs/OxideCap*here->MOS2m* here->MOS2w*EffectiveLength+cdonco; @@ -686,20 +686,20 @@ next1: if(vbs <= -3*vt) { * compute some more useful quantities */ - sarg3 = sarg*sarg*sarg; + sarg3 = sarg1*sarg1*sarg1; /* XXX constant per model */ sbiarg = sqrt(here->MOS2tBulkPot); gammad = gamasd; dgdvbs = dgddvb; body = barg*barg*barg-sarg3; - gdbdv = 2.0*gammad*(barg*barg*dbrgdb-sarg*sarg*dsrgdb); - dodvbs = -factor+dgdvbs*sarg+gammad*dsrgdb; + gdbdv = 2.0*gammad*(barg*barg*dbrgdb-sarg1*sarg1*dsrgdb); + dodvbs = -factor+dgdvbs*sarg1+gammad*dsrgdb; if (model->MOS2fastSurfaceStateDensity == 0.0) goto line400; if (OxideCap == 0.0) goto line410; - dxndvb = 2.0*dgdvbs*dsrgdb+gammad*d2sdb2+dgddb2*sarg; + dxndvb = 2.0*dgdvbs*dsrgdb+gammad*d2sdb2+dgddb2*sarg1; dodvbs = dodvbs+vt*dxndvb; dxndvd = dgdvds*dsrgdb; - dodvds = dgdvds*sarg+vt*dxndvd; + dodvds = dgdvds*sarg1+vt*dxndvd; /* * evaluate effective mobility and its derivatives */ @@ -740,12 +740,12 @@ line500: dsdvgs = 0.0; dsdvbs = 0.0; } else { - arg = sqrt(1.0+4.0*argv/gammd2); - vdsat = (vgsx-vbin)/eta+gammd2*(1.0-arg)/2.0; + arg1 = sqrt(1.0+4.0*argv/gammd2); + vdsat = (vgsx-vbin)/eta+gammd2*(1.0-arg1)/2.0; vdsat = MAX(vdsat,0.0); - dsdvgs = (1.0-1.0/arg)/eta; - dsdvbs = (gammad*(1.0-arg)+2.0*argv/(gammad*arg))/ - eta*dgdvbs+1.0/arg+factor*dsdvgs; + dsdvgs = (1.0-1.0/arg1)/eta; + dsdvbs = (gammad*(1.0-arg1)+2.0*argv/(gammad*arg1))/ + eta*dgdvbs+1.0/arg1+factor*dsdvgs; } } else { vdsat = (vgsx-vbin)/eta; @@ -838,15 +838,15 @@ line500: dbsrdb = -0.5*bsarg*bsarg/sphi3; } bodys = bsarg*bsarg*bsarg-sarg3; - gdbdvs = 2.0*gammad*(bsarg*bsarg*dbsrdb-sarg*sarg*dsrgdb); + gdbdvs = 2.0*gammad*(bsarg*bsarg*dbsrdb-sarg1*sarg1*dsrgdb); if (model->MOS2maxDriftVel <= 0) { if (model->MOS2substrateDoping == 0.0) goto line610; if (xlamda > 0.0) goto line610; argv = (lvds-vdsat)/4.0; sargv = sqrt(1.0+argv*argv); - arg = sqrt(argv+sargv); + arg1 = sqrt(argv+sargv); xlfact = model->MOS2xd/(EffectiveLength*lvds); - xlamda = xlfact*arg; + xlamda = xlfact*arg1; dldsat = lvds*xlamda/(8.0*sargv); } else { argv = (vgsx-vbin)/eta-vdsat; @@ -915,13 +915,13 @@ line610: goto line1050; } - here->MOS2gds = beta1*(von-vbin-gammad*sarg)*exp(argg* + here->MOS2gds = beta1*(von-vbin-gammad*sarg1)*exp(argg* (lvgs-von)); goto line1050; } - here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg); + here->MOS2gds = beta1*(lvgs-vbin-gammad*sarg1); goto line1050; } @@ -971,25 +971,25 @@ line900: * linear region */ cdrain = beta1*((lvgs-vbin-eta*lvds/2.0)*lvds-gammad*body/1.5); - arg = cdrain*(dudvgs/ufact-dldvgs/clfact); - here->MOS2gm = arg+beta1*lvds; - arg = cdrain*(dudvds/ufact-dldvds/clfact); - here->MOS2gds = arg+beta1*(lvgs-vbin-eta* + arg1 = cdrain*(dudvgs/ufact-dldvgs/clfact); + here->MOS2gm = arg1+beta1*lvds; + arg1 = cdrain*(dudvds/ufact-dldvds/clfact); + here->MOS2gds = arg1+beta1*(lvgs-vbin-eta* lvds-gammad*barg-dgdvds*body/1.5); - arg = cdrain*(dudvbs/ufact-dldvbs/clfact); - here->MOS2gmbs = arg-beta1*(gdbdv+dgdvbs*body/1.5-factor*lvds); + arg1 = cdrain*(dudvbs/ufact-dldvbs/clfact); + here->MOS2gmbs = arg1-beta1*(gdbdv+dgdvbs*body/1.5-factor*lvds); } else { /* * saturation region */ cdrain = beta1*((lvgs-vbin-eta* vdsat/2.0)*vdsat-gammad*bodys/1.5); - arg = cdrain*(dudvgs/ufact-dldvgs/clfact); - here->MOS2gm = arg+beta1*vdsat+beta1*(lvgs- + arg1 = cdrain*(dudvgs/ufact-dldvgs/clfact); + here->MOS2gm = arg1+beta1*vdsat+beta1*(lvgs- vbin-eta*vdsat-gammad*bsarg)*dsdvgs; here->MOS2gds = -cdrain*dldvds/clfact-beta1*dgdvds*bodys/1.5; - arg = cdrain*(dudvbs/ufact-dldvbs/clfact); - here->MOS2gmbs = arg-beta1*(gdbdvs+dgdvbs*bodys/1.5-factor* + arg1 = cdrain*(dudvbs/ufact-dldvbs/clfact); + here->MOS2gmbs = arg1-beta1*(gdbdvs+dgdvbs*bodys/1.5-factor* vdsat)+beta1* (lvgs-vbin-eta*vdsat-gammad*bsarg)*dsdvbs; } /* diff --git a/src/spicelib/devices/mos2/mos2par.c b/src/spicelib/devices/mos2/mos2par.c index a818f7602..732be5471 100644 --- a/src/spicelib/devices/mos2/mos2par.c +++ b/src/spicelib/devices/mos2/mos2par.c @@ -29,7 +29,7 @@ MOS2param(int param, IFvalue *value, GENinstance *inst, if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) { + switch (param) { case MOS2_TEMP: here->MOS2temp = value->rValue+CONSTCtoK; here->MOS2tempGiven = TRUE; @@ -90,13 +90,17 @@ MOS2param(int param, IFvalue *value, GENinstance *inst, here->MOS2icVGSGiven = TRUE; break; case MOS2_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->MOS2icVBS = *(value->v.vec.rVec+2); here->MOS2icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->MOS2icVGS = *(value->v.vec.rVec+1); here->MOS2icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MOS2icVDS = *(value->v.vec.rVec); here->MOS2icVDSGiven = TRUE; diff --git a/src/spicelib/devices/mos3/mos3par.c b/src/spicelib/devices/mos3/mos3par.c index dea7b2421..725700a90 100644 --- a/src/spicelib/devices/mos3/mos3par.c +++ b/src/spicelib/devices/mos3/mos3par.c @@ -28,8 +28,7 @@ MOS3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) { - + switch (param) { case MOS3_M: here->MOS3m = value->rValue; here->MOS3mGiven = TRUE; @@ -90,13 +89,17 @@ MOS3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->MOS3dtempGiven = TRUE; break; case MOS3_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->MOS3icVBS = *(value->v.vec.rVec+2); here->MOS3icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->MOS3icVGS = *(value->v.vec.rVec+1); here->MOS3icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MOS3icVDS = *(value->v.vec.rVec); here->MOS3icVDSGiven = TRUE; diff --git a/src/spicelib/devices/mos6/mos6load.c b/src/spicelib/devices/mos6/mos6load.c index a334393ea..8ab2d0281 100644 --- a/src/spicelib/devices/mos6/mos6load.c +++ b/src/spicelib/devices/mos6/mos6load.c @@ -464,8 +464,8 @@ next1: if(vbs <= -3*vt) { /* the following 14 variables are local to this code block until * it is obvious that they can be made global */ - double arg; - double sarg; + double arg1; + double sarg1; double vgon; double vdshere, vbsvbd; double idsat, lambda, vonbm = 0.0; @@ -473,14 +473,14 @@ next1: if(vbs <= -3*vt) { vbsvbd = (here->MOS6mode==1?vbs:vbd); if (vbsvbd <= 0 ) { - sarg = sqrt(here->MOS6tPhi - vbsvbd); + sarg1 = sqrt(here->MOS6tPhi - vbsvbd); } else { - sarg = sqrt(here->MOS6tPhi); - sarg = sarg - vbsvbd / (sarg+sarg); - sarg = MAX(0,sarg); + sarg1 = sqrt(here->MOS6tPhi); + sarg1 = sarg1 - vbsvbd / (sarg1+sarg1); + sarg1 = MAX(0,sarg1); } vdshere = vds * here->MOS6mode; - von=(here->MOS6tVbi*model->MOS6type)+model->MOS6gamma*sarg + von=(here->MOS6tVbi*model->MOS6type)+model->MOS6gamma*sarg1 - model->MOS6gamma1 * vbsvbd - model->MOS6sigma * vdshere; vgon = (here->MOS6mode==1?vgs:vgd) - von; @@ -496,20 +496,20 @@ next1: if(vbs <= -3*vt) { here->MOS6gmbs=0; } else { - if (sarg <= 0) { - arg=0; + if (sarg1 <= 0) { + arg1=0; } else { if ((here->MOS6mode==1?vbs:vbd) <= 0 ) { vonbm = model->MOS6gamma1 - + model->MOS6gamma / (sarg + sarg); + + model->MOS6gamma / (sarg1 + sarg1); } else { vonbm = model->MOS6gamma1 + model->MOS6gamma / 2 / sqrt(here->MOS6tPhi); } } - sarg = log(vgon); - vdsat = model->MOS6kv * exp(sarg * model->MOS6nv); - idsat = betac * exp(sarg * model->MOS6nc); + sarg1 = log(vgon); + vdsat = model->MOS6kv * exp(sarg1 * model->MOS6nv); + idsat = betac * exp(sarg1 * model->MOS6nc); lambda = model->MOS6lamda0 - model->MOS6lamda1 * vbsvbd; /* * saturation region diff --git a/src/spicelib/devices/mos6/mos6par.c b/src/spicelib/devices/mos6/mos6par.c index a3f526f99..a26d76248 100644 --- a/src/spicelib/devices/mos6/mos6par.c +++ b/src/spicelib/devices/mos6/mos6par.c @@ -21,7 +21,7 @@ MOS6param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case MOS6_TEMP: here->MOS6temp = value->rValue+CONSTCtoK; here->MOS6tempGiven = TRUE; @@ -82,13 +82,17 @@ MOS6param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->MOS6icVGSGiven = TRUE; break; case MOS6_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->MOS6icVBS = *(value->v.vec.rVec+2); here->MOS6icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->MOS6icVGS = *(value->v.vec.rVec+1); here->MOS6icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MOS6icVDS = *(value->v.vec.rVec); here->MOS6icVDSGiven = TRUE; diff --git a/src/spicelib/devices/mos9/mos9par.c b/src/spicelib/devices/mos9/mos9par.c index c8f3c9fdb..f31fa4ff5 100644 --- a/src/spicelib/devices/mos9/mos9par.c +++ b/src/spicelib/devices/mos9/mos9par.c @@ -23,8 +23,7 @@ MOS9param(int param, IFvalue *value, GENinstance *inst, NG_IGNORE(select); - switch(param) { - + switch (param) { case MOS9_M: here->MOS9m = value->rValue; here->MOS9mGiven = TRUE; @@ -85,13 +84,17 @@ MOS9param(int param, IFvalue *value, GENinstance *inst, here->MOS9dtempGiven = TRUE; break; case MOS9_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 3: here->MOS9icVBS = *(value->v.vec.rVec+2); here->MOS9icVBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->MOS9icVGS = *(value->v.vec.rVec+1); here->MOS9icVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->MOS9icVDS = *(value->v.vec.rVec); here->MOS9icVDSGiven = TRUE; diff --git a/src/spicelib/devices/soi3/soi3par.c b/src/spicelib/devices/soi3/soi3par.c index e621c891d..7650d1fd3 100644 --- a/src/spicelib/devices/soi3/soi3par.c +++ b/src/spicelib/devices/soi3/soi3par.c @@ -36,7 +36,7 @@ SOI3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case SOI3_L: here->SOI3l = value->rValue; here->SOI3lGiven = TRUE; @@ -133,16 +133,21 @@ SOI3param(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->SOI3ct4Given = TRUE; break; case SOI3_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 4: here->SOI3icVBS = *(value->v.vec.rVec+3); here->SOI3icVBSGiven = TRUE; + /* FALLTHROUGH */ case 3: here->SOI3icVGBS = *(value->v.vec.rVec+2); here->SOI3icVGBSGiven = TRUE; + /* FALLTHROUGH */ case 2: here->SOI3icVGFS = *(value->v.vec.rVec+1); here->SOI3icVGFSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->SOI3icVDS = *(value->v.vec.rVec); here->SOI3icVDSGiven = TRUE; diff --git a/src/spicelib/devices/tra/traparam.c b/src/spicelib/devices/tra/traparam.c index 21606607e..7f302feb8 100644 --- a/src/spicelib/devices/tra/traparam.c +++ b/src/spicelib/devices/tra/traparam.c @@ -20,7 +20,7 @@ TRAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case TRA_RELTOL: here->TRAreltol = value->rValue; here->TRAreltolGiven = TRUE; @@ -62,13 +62,18 @@ TRAparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->TRAicC2Given = TRUE; break; case TRA_IC: - switch(value->v.numValue){ + /* FALLTHROUGH ded to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 4: here->TRAinitCur2 = *(value->v.vec.rVec+3); + /* FALLTHROUGH */ case 3: here->TRAinitVolt2 = *(value->v.vec.rVec+2); + /* FALLTHROUGH */ case 2: here->TRAinitCur1 = *(value->v.vec.rVec+1); + /* FALLTHROUGH */ case 1: here->TRAinitVolt1 = *(value->v.vec.rVec); break; diff --git a/src/spicelib/devices/txl/txlload.c b/src/spicelib/devices/txl/txlload.c index 22a0d66df..9926bf975 100644 --- a/src/spicelib/devices/txl/txlload.c +++ b/src/spicelib/devices/txl/txlload.c @@ -609,21 +609,20 @@ right_consts_txl(TXLine *tx, int t, int time, double h, double h1, int l1, int l } -static int -update_delayed_cnv_txl(TXLine *tx, double h) +static int update_delayed_cnv_txl(TXLine *tx, double h) { - double ratio; + double ratio1; double f; VI_list_txl *vi; TERM *tms; h *= 0.5e-12; - ratio = tx->ratio; + ratio1 = tx->ratio; vi = tx->vi_tail; - if (ratio > 0.0) { + if (ratio1 > 0.0) { tms = tx->h3_term; - f = h * ratio * vi->v_i; + f = h * ratio1 * vi->v_i; tms[0].cnv_i += f * tms[0].c; tms[1].cnv_i += f * tms[1].c; tms[2].cnv_i += f * tms[2].c; @@ -631,7 +630,7 @@ update_delayed_cnv_txl(TXLine *tx, double h) tms[4].cnv_i += f * tms[4].c; tms[5].cnv_i += f * tms[5].c; - f = h * ratio * vi->v_o; + f = h * ratio1 * vi->v_o; tms[0].cnv_o += f * tms[0].c; tms[1].cnv_o += f * tms[1].c; tms[2].cnv_o += f * tms[2].c; @@ -640,12 +639,12 @@ update_delayed_cnv_txl(TXLine *tx, double h) tms[5].cnv_o += f * tms[5].c; tms = tx->h2_term; - f = h * ratio * vi->i_i; + f = h * ratio1 * vi->i_i; tms[0].cnv_i += f * tms[0].c; tms[1].cnv_i += f * tms[1].c; tms[2].cnv_i += f * tms[2].c; - f = h * ratio * vi->i_o; + f = h * ratio1 * vi->i_o; tms[0].cnv_o += f * tms[0].c; tms[1].cnv_o += f * tms[1].c; tms[2].cnv_o += f * tms[2].c; diff --git a/src/spicelib/devices/txl/txlsetup.c b/src/spicelib/devices/txl/txlsetup.c index bd2a5ef2a..55b2dbf39 100644 --- a/src/spicelib/devices/txl/txlsetup.c +++ b/src/spicelib/devices/txl/txlsetup.c @@ -571,24 +571,24 @@ Gaussian_Elimination1(int dims) return(1); } -static double -root3(double a1, double a2, double a3, double x) +static double root3(double a1_in, double a2_in, double a3_in, double x) { double t1, t2; - t1 = x*x*x + a1*x*x + a2*x + a3; - t2 = 3.0*x*x + 2.0*a1*x + a2; + t1 = x*x*x + a1_in*x*x + a2_in*x + a3_in; + t2 = 3.0*x*x + 2.0*a1_in*x + a2_in; return(x - t1 / t2); } static int -div3(double a1, double a2, double a3, double x, double *p1, double *p2) +div3(double a1_in, double a2_in, double a3_in, + double x, double *p1_in, double *p2_in) { - NG_IGNORE(a2); + NG_IGNORE(a2_in); - *p1 = a1 + x; - *p2 = - a3 / x; + *p1_in = a1_in + x; + *p2_in = -a3_in / x; return(1); } @@ -656,8 +656,8 @@ static double f2(a, b, z) } ***/ -static int -mac(double at, double bt, double *b1, double *b2, double *b3, double *b4, double *b5) +static int mac(double at, double bt, double *b1_in, double *b2_in, + double *b3_in, double *b4_in, double *b5_in) /* float at, bt; */ { double a, b; @@ -666,7 +666,7 @@ mac(double at, double bt, double *b1, double *b2, double *b3, double *b4, double a = at; b = bt; - y1 = *b1 = 0.5 * (a - b); + y1 = *b1_in = 0.5 * (a - b); y2 = 0.5 * (3.0 * b * b - 2.0 * a * b - a * a) * y1 / (a - b); y3 = ((3.0 * b * b + a * a) * y1 * y1 + 0.5 * (3.0 * b * b - 2.0 * a * b - a * a) * y2) / (a - b); @@ -678,12 +678,12 @@ mac(double at, double bt, double *b1, double *b2, double *b3, double *b4, double (y2 * y2 + y1 * y3) + (3.0 * b * b + a * a) * y1 * y3 + 0.5 * (3.0 * b * b - 2.0 * a * b - a * a) * y4) / (a - b); - *b2 = y2 / 2.0; - *b3 = y3 / 6.0; - *b4 = y4 / 24.0; - *b5 = y5 / 120.0; + *b2_in = y2 / 2.0; + *b3_in = y3 / 6.0; + *b4_in = y4 / 24.0; + *b5_in = y5 / 120.0; - return(1); + return 1; } @@ -705,19 +705,18 @@ static double exp_approx1(double st) } ***/ -static int -get_c(double eq1, double eq2, double eq3, double ep1, double ep2, double a, double b, - double *cr, double *ci) +static int get_c(double eq1_in, double eq2_in, double eq3_in, + double ep1_in, double ep2_in, double a, double b, double *cr, double *ci) { double d, n; - d = (3.0*(a*a-b*b)+2.0*ep1*a+ep2)*(3.0*(a*a-b*b)+2.0*ep1*a+ep2); - d += (6.0*a*b+2.0*ep1*b)*(6.0*a*b+2.0*ep1*b); - n = -(eq1*(a*a-b*b)+eq2*a+eq3)*(6.0*a*b+2.0*ep1*b); - n += (2.0*eq1*a*b+eq2*b)*(3.0*(a*a-b*b)+2.0*ep1*a+ep2); + d = (3.0*(a*a-b*b)+2.0*ep1_in*a+ep2_in)*(3.0*(a*a-b*b)+2.0*ep1_in*a+ep2_in); + d += (6.0*a*b+2.0*ep1_in*b)*(6.0*a*b+2.0*ep1_in*b); + n = -(eq1_in*(a*a-b*b)+eq2_in*a+eq3_in)*(6.0*a*b+2.0*ep1_in*b); + n += (2.0*eq1_in*a*b+eq2_in*b)*(3.0*(a*a-b*b)+2.0*ep1_in*a+ep2_in); *ci = n/d; - n = (3.0*(a*a-b*b)+2.0*ep1*a+ep2)*(eq1*(a*a-b*b)+eq2*a+eq3); - n += (6.0*a*b+2.0*ep1*b)*(2.0*eq1*a*b+eq2*b); + n = (3.0*(a*a-b*b)+2.0*ep1_in*a+ep2_in)*(eq1_in*(a*a-b*b)+eq2_in*a+eq3_in); + n += (6.0*a*b+2.0*ep1_in*b)*(2.0*eq1_in*a*b+eq2_in*b); *cr = n/d; return(1); @@ -947,41 +946,44 @@ exp_div3(double a1, double a2, double a3, double x, /*** ***/ -static int -exp_find_roots(double a1, double a2, double a3, double *ex1, double *ex2, double *ex3) +static int exp_find_roots(double a1_in, double a2_in, double a3_in, + double *ex1_in, double *ex2_in, double *ex3_in) { double x, t; double p, q; - q = (a1*a1-3.0*a2) / 9.0; - p = (2.0*a1*a1*a1-9.0*a1*a2+27.0*a3) / 54.0; + q = (a1_in*a1_in-3.0*a2_in) / 9.0; + p = (2.0*a1_in*a1_in*a1_in-9.0*a1_in*a2_in+27.0*a3_in) / 54.0; t = q*q*q - p*p; if (t >= 0.0) { t = acos(p /(q * sqrt(q))); - x = -2.0*sqrt(q)*cos(t / 3.0) - a1/3.0; + x = -2.0*sqrt(q)*cos(t / 3.0) - a1_in/3.0; } else { if (p > 0.0) { t = pow(sqrt(-t)+p, 1.0 / 3.0); - x = -(t + q / t) - a1/3.0; + x = -(t + q / t) - a1_in/3.0; } else if (p == 0.0) { - x = -a1/3.0; + x = -a1_in/3.0; } else { t = pow(sqrt(-t)-p, 1.0 / 3.0); - x = (t + q / t) - a1/3.0; + x = (t + q / t) - a1_in/3.0; } } - { - double ex1; - int i = 0; - ex1 = x; - for (t = root3(a1, a2, a3, x); ABS(t-x) > 5.0e-4; - t = root3(a1, a2, a3, x)) - if (++i == 32) { - x = ex1; - break; - } else - x = t; - } + { + double ex1a; + int i = 0; + ex1a = x; + for (t = root3(a1_in, a2_in, a3_in, x); ABS(t-x) > 5.0e-4; + t = root3(a1_in, a2_in, a3_in, x)) { + if (++i == 32) { + x = ex1a; + break; + } + else { + x = t; + } + } + } /*** x = a1; for (t = root3(a1, a2, a3, x); ABS(t-x) > epsi2; @@ -997,24 +999,24 @@ exp_find_roots(double a1, double a2, double a3, double *ex1, double *ex2, double } } ***/ - *ex1 = x; - div3(a1, a2, a3, x, &a1, &a2); + *ex1_in = x; + div3(a1_in, a2_in, a3_in, x, &a1_in, &a2_in); - t = a1 * a1 - 4.0 * a2; + t = a1_in * a1_in - 4.0 * a2_in; if (t < 0) { ifImg = 1; printf("***** Two Imaginary Roots.\n"); - *ex3 = 0.5 * sqrt(-t); - *ex2 = -0.5 * a1; + *ex3_in = 0.5 * sqrt(-t); + *ex2_in = -0.5 * a1_in; } else { ifImg = 0; t *= 1.0e-16; t = sqrt(t)*1.0e8; - if (a1 >= 0.0) - *ex2 = t = -0.5 * (a1 + t); + if (a1_in >= 0.0) + *ex2_in = t = -0.5 * (a1_in + t); else - *ex2 = t = -0.5 * (a1 - t); - *ex3 = a2 / t; + *ex2_in = t = -0.5 * (a1_in - t); + *ex3_in = a2_in / t; /* *ex2 = 0.5 * (-a1 + t); *ex3 = 0.5 * (-a1 - t); @@ -1095,34 +1097,34 @@ static NODE return(n); } -static int -find_roots(double a1, double a2, double a3, double *x1, double *x2, double *x3) +static int find_roots(double a1_in, double a2_in, double a3_in, + double *x1r, double *x2r, double *x3r) { double x, t; double p, q; - q = (a1*a1-3.0*a2) / 9.0; - p = (2.0*a1*a1*a1-9.0*a1*a2+27.0*a3) / 54.0; + q = (a1_in*a1_in-3.0*a2_in) / 9.0; + p = (2.0*a1_in*a1_in*a1_in-9.0*a1_in*a2_in+27.0*a3_in) / 54.0; t = q*q*q - p*p; if (t >= 0.0) { t = acos(p /(q * sqrt(q))); - x = -2.0*sqrt(q)*cos(t / 3.0) - a1/3.0; + x = -2.0*sqrt(q)*cos(t / 3.0) - a1_in/3.0; } else { if (p > 0.0) { t = pow(sqrt(-t)+p, 1.0 / 3.0); - x = -(t + q / t) - a1/3.0; + x = -(t + q / t) - a1_in/3.0; } else if (p == 0.0) { - x = -a1/3.0; + x = -a1_in/3.0; } else { t = pow(sqrt(-t)-p, 1.0 / 3.0); - x = (t + q / t) - a1/3.0; + x = (t + q / t) - a1_in/3.0; } } { double x_backup = x; int i = 0; - for (t = root3(a1, a2, a3, x); ABS(t-x) > 5.0e-4; - t = root3(a1, a2, a3, x)) + for (t = root3(a1_in, a2_in, a3_in, x); ABS(t-x) > 5.0e-4; + t = root3(a1_in, a2_in, a3_in, x)) if (++i == 32) { x = x_backup; break; @@ -1147,10 +1149,10 @@ find_roots(double a1, double a2, double a3, double *x1, double *x2, double *x3) } */ - *x1 = x; - div3(a1, a2, a3, x, &a1, &a2); + *x1r = x; + div3(a1_in, a2_in, a3_in, x, &a1_in, &a2_in); - t = a1 * a1 - 4.0 * a2; + t = a1_in * a1_in - 4.0 * a2_in; if (t < 0) { printf("***** Two Imaginary Roots in Characteristic Admittance.\n"); controlled_exit(EXIT_FAILURE); @@ -1158,11 +1160,11 @@ find_roots(double a1, double a2, double a3, double *x1, double *x2, double *x3) t *= 1.0e-18; t = sqrt(t) * 1.0e9; - if (a1 >= 0.0) - *x2 = t = -0.5 * (a1 + t); + if (a1_in >= 0.0) + *x2r = t = -0.5 * (a1_in + t); else - *x2 = t = -0.5 * (a1 - t); - *x3 = a2 / t; + *x2r = t = -0.5 * (a1_in - t); + *x3r = a2_in / t; /* *x2 = 0.5 * (-a1 + t); *x3 = 0.5 * (-a1 - t); diff --git a/src/spicelib/devices/vbic/vbicparam.c b/src/spicelib/devices/vbic/vbicparam.c index 34e14bbc3..5ffea4cc4 100644 --- a/src/spicelib/devices/vbic/vbicparam.c +++ b/src/spicelib/devices/vbic/vbicparam.c @@ -26,7 +26,7 @@ VBICparam(int param, IFvalue *value, GENinstance *instPtr, IFvalue *select) NG_IGNORE(select); - switch(param) { + switch (param) { case VBIC_AREA: here->VBICarea = value->rValue; here->VBICareaGiven = TRUE; @@ -55,10 +55,13 @@ VBICparam(int param, IFvalue *value, GENinstance *instPtr, IFvalue *select) here->VBICmGiven = TRUE; break; case VBIC_IC : - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->VBICicVCE = *(value->v.vec.rVec+1); here->VBICicVCEGiven = TRUE; + /* FALLTHROUGH */ case 1: here->VBICicVBE = *(value->v.vec.rVec); here->VBICicVBEGiven = TRUE; diff --git a/src/spicelib/devices/vdmos/vdmospar.c b/src/spicelib/devices/vdmos/vdmospar.c index fef9de1bf..6da271f76 100644 --- a/src/spicelib/devices/vdmos/vdmospar.c +++ b/src/spicelib/devices/vdmos/vdmospar.c @@ -29,7 +29,7 @@ VDMOSparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) if (!cp_getvar("scale", CP_REAL, &scale, 0)) scale = 1; - switch(param) { + switch (param) { case VDMOS_TEMP: here->VDMOStemp = value->rValue+CONSTCtoK; here->VDMOStempGiven = TRUE; @@ -66,10 +66,13 @@ VDMOSparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) here->VDMOSthermalGiven = TRUE; break; case VDMOS_IC: - switch(value->v.numValue){ + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->VDMOSicVGS = *(value->v.vec.rVec+1); here->VDMOSicVGSGiven = TRUE; + /* FALLTHROUGH */ case 1: here->VDMOSicVDS = *(value->v.vec.rVec); here->VDMOSicVDSGiven = TRUE; diff --git a/src/spicelib/devices/vsrc/vsrcpar.c b/src/spicelib/devices/vsrc/vsrcpar.c index c14e39f8d..ccc7c5462 100644 --- a/src/spicelib/devices/vsrc/vsrcpar.c +++ b/src/spicelib/devices/vsrc/vsrcpar.c @@ -38,8 +38,7 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) NG_IGNORE(select); - switch(param) { - + switch (param) { case VSRC_DC: here->VSRCdcValue = value->rValue; here->VSRCdcGiven = TRUE; @@ -58,13 +57,17 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) break; case VSRC_AC: - switch(value->v.numValue) { + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ + switch (value->v.numValue) { case 2: here->VSRCacPhase = *(value->v.vec.rVec+1); here->VSRCacPGiven = TRUE; + /* FALLTHROUGH */ case 1: here->VSRCacMag = *(value->v.vec.rVec); here->VSRCacMGiven = TRUE; + /* FALLTHROUGH */ case 0: here->VSRCacGiven = TRUE; break; @@ -161,7 +164,7 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) case VSRC_D_F1: here->VSRCdF1given = TRUE; here->VSRCdGiven = TRUE; - switch(value->v.numValue) { + switch (value->v.numValue) { case 2: here->VSRCdF1phase = *(value->v.vec.rVec+1); here->VSRCdF1mag = *(value->v.vec.rVec); @@ -182,7 +185,7 @@ VSRCparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select) case VSRC_D_F2: here->VSRCdF2given = TRUE; here->VSRCdGiven = TRUE; - switch(value->v.numValue) { + switch (value->v.numValue) { case 2: here->VSRCdF2phase = *(value->v.vec.rVec+1); here->VSRCdF2mag = *(value->v.vec.rVec); diff --git a/src/spicelib/parser/inpptree.c b/src/spicelib/parser/inpptree.c index 92e1d8766..e9792cb53 100644 --- a/src/spicelib/parser/inpptree.c +++ b/src/spicelib/parser/inpptree.c @@ -1441,6 +1441,8 @@ void free_tree(INPparseNode *pt) controlled_exit(1); } + /* FALLTHROUGH added to suppress GCC warning due to + * -Wimplicit-fallthrough flag */ switch (pt->type) { case PT_TIME: case PT_TEMPERATURE: @@ -1457,6 +1459,7 @@ void free_tree(INPparseNode *pt) case PT_COMMA: case PT_TERN: dec_usage(pt->right); + /* FALLTHROUGH */ case PT_FUNCTION: dec_usage(pt->left); break; diff --git a/src/xspice/cmpp/file_buffer.c b/src/xspice/cmpp/file_buffer.c index 992feb5be..74e602a4c 100644 --- a/src/xspice/cmpp/file_buffer.c +++ b/src/xspice/cmpp/file_buffer.c @@ -456,7 +456,7 @@ static size_t fb_make_space_at_end(FILEBUF *p_fb) /* Shift data in use to the front of the buffer if not already */ if (p_dst != p_src) { /* object is not at start of buffer */ - const size_t n = p_fb->p_data_end - p_src; + const size_t n = (size_t) (p_fb->p_data_end - p_src); if (n > 0) { /* Will be 0 if skipping whitespace and comments */ (void) memmove(p_dst, p_src, n); } @@ -502,7 +502,7 @@ static size_t fb_make_space_at_end(FILEBUF *p_fb) } } - return p_fb->p_buf_end - p_fb->p_data_end; + return (size_t) (p_fb->p_buf_end - p_fb->p_data_end); } /* end of function fb_make_space_at_end */ @@ -597,7 +597,7 @@ static int fb_skip_to_eol(FILEBUF *p_fb) static int fb_return_string(FILEBUF *p_fb, FBSTRING *p_fbstr) { const char *p_data_start = p_fbstr->sz = p_fb->p_obj_start; - p_fbstr->n_char = p_fb->p_obj_end - p_data_start; + p_fbstr->n_char = (size_t) (p_fb->p_obj_end - p_data_start); return 0; } /* end of function fb_return_string */ diff --git a/src/xspice/cmpp/pp_lst.c b/src/xspice/cmpp/pp_lst.c index 4b1f12be7..297d83b08 100644 --- a/src/xspice/cmpp/pp_lst.c +++ b/src/xspice/cmpp/pp_lst.c @@ -211,10 +211,10 @@ void preprocess_lst_files(void) /* Free allocations */ if (model_info != (Model_Info_t *) NULL) { - free_model_info(num_models, model_info); + free_model_info((int) num_models, model_info); } if (node_info != (Node_Info_t *) NULL) { - free_node_info(num_nodes, node_info); + free_node_info((int) num_nodes, node_info); } } /* end of function preprocess_lst_files */ @@ -402,12 +402,12 @@ EXITPOINT: /* If error, free model info */ if (xrc != 0) { - free_model_info(n_model_info, p_model_info); + free_model_info((int) n_model_info, p_model_info); n_model_info = 0; p_model_info = (Model_Info_t *) NULL; } - *p_num_model_info = n_model_info; + *p_num_model_info = (int) n_model_info; *pp_model_info = p_model_info; return xrc; @@ -544,12 +544,12 @@ EXITPOINT: /* If error, free node info */ if (xrc != 0) { - free_node_info(n_node_info, p_node_info); + free_node_info((int) n_node_info, p_node_info); n_node_info = 0; p_node_info = (Node_Info_t *) NULL; } - *p_num_node_info = n_node_info; + *p_num_node_info = (int) n_node_info; *pp_node_info = p_node_info; return xrc; @@ -841,8 +841,8 @@ static int check_uniqueness( } /* Sizes of models and nodes */ - const unsigned int n_model = (unsigned int) numSPICEmodels + num_models; - const unsigned int n_node = (unsigned int) numUDNidentifiers + num_nodes; + const unsigned int n_model = (unsigned int) (numSPICEmodels + num_models); + const unsigned int n_node = (unsigned int) (numUDNidentifiers + num_nodes); const unsigned int n_ks = n_model > n_node ? n_model : n_node; /* Allocate structure to compare */ @@ -890,8 +890,8 @@ static int check_uniqueness( } /* Test for duplicates */ - f_have_duplicate |= test_for_duplicates(num_models, p_ks, - &report_error_function_name); + f_have_duplicate |= test_for_duplicates((unsigned int) num_models, + p_ks, &report_error_function_name); } } @@ -1394,14 +1394,14 @@ static int read_udn_type_name( c = fgetc(fp); if(c == '"') { found = true; - if (i >= sizeof name) { + if (i >= (int) sizeof name) { print_error("name too long"); exit(1); } name[i] = '\0'; } else if(c != EOF) { - if (i > sizeof name) { + if (i > (int) sizeof name) { print_error("name too long"); exit(1); } diff --git a/src/xspice/cmpp/writ_ifs.c b/src/xspice/cmpp/writ_ifs.c index e1ab2d5e6..3438751dc 100644 --- a/src/xspice/cmpp/writ_ifs.c +++ b/src/xspice/cmpp/writ_ifs.c @@ -1220,7 +1220,7 @@ static char *value_to_str(Data_Type_t type, Value_t value) /* be careful, the string could conceivably be very long... */ str_len = (int) strlen(value.svalue); if ((str_len + BASE_STR_LEN) > max_len) { - size_t n_byte_alloc = max_len + str_len + 1; + size_t n_byte_alloc = (size_t) (max_len + str_len + 1); void * const p = realloc(str, n_byte_alloc); if (p == NULL) { (void) fprintf(stderr, "Unable to resize string " diff --git a/src/xspice/icm/GNUmakefile.in b/src/xspice/icm/GNUmakefile.in index ad4a2734a..740865c52 100644 --- a/src/xspice/icm/GNUmakefile.in +++ b/src/xspice/icm/GNUmakefile.in @@ -43,23 +43,13 @@ clean: #----------------------------------------------------------------------------- -NGSRCDIR = $(srcdir)/../../ +NGSRCDIR = $(srcdir)/../.. -dstring.o : $(NGSRCDIR)/misc/dstring.c $(NGSRCDIR)/include/ngspice/dstring.h - $(COMPILE) -I $(NGSRCDIR)/include -o $@ -c $< +dstring.o: $(NGSRCDIR)/misc/dstring.c $(NGSRCDIR)/include/ngspice/dstring.h + $(CC) $(CFLAGS) -I$(NGSRCDIR)/include -fPIC -o $@ -c $< ifdef cm -# These will work for a simpler format of the .lst files with # comments and -# version information on the same line. -# sed removes comment lines of form [space]#[text] -# awk keeps the name of the path only, removing version number if present -# $$ and \# are escapes for Makefile -#modlst := $(shell cat $(srcdir)/$(cm)/modpath.lst | sed -e '/^[ \t]*\#/d' |\ -# awk '{ print $$1 }') -#udnlst := $(shell cat $(srcdir)/$(cm)/udnpath.lst | sed -e '/^[ \t]*\#/d' |\ -# awk '{ print $$1 }') - ifeq ($(OS),Windows_NT) cmpp = ../cmpp/cmpp.exe else diff --git a/src/xspice/icm/analog/file_source/cfunc.mod b/src/xspice/icm/analog/file_source/cfunc.mod index 937875b8a..f140831a5 100644 --- a/src/xspice/icm/analog/file_source/cfunc.mod +++ b/src/xspice/icm/analog/file_source/cfunc.mod @@ -81,7 +81,7 @@ struct filesource_state { struct infiledata { double *datavec; - int vecallocated; + size_t vecallocated; int maxoccupied; int actpointer; int size; @@ -189,7 +189,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc. loc->indata = (struct infiledata *) malloc( sizeof(struct infiledata)); loc->indata->datavec = (double *) malloc(sizeof(double) * - stepsize * 1000); + (size_t) (stepsize * 1000)); /* Check allocations */ if (loc->timeinterval == (double *) NULL || @@ -205,7 +205,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc. CALLBACK = cm_filesource_callback; - loc->indata->vecallocated = stepsize * 1000; + loc->indata->vecallocated = (size_t) (stepsize * 1000); loc->indata->maxoccupied = 0; loc->indata->actpointer = 0; loc->indata->size = stepsize; @@ -280,8 +280,8 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc. /* before storing, check if vector size is large enough. If not, add another 1000*size doubles */ - if (count > loc->indata->vecallocated - size) { - loc->indata->vecallocated += size * 1000; + if (count > (int) loc->indata->vecallocated - size) { + loc->indata->vecallocated += (size_t) (size * 1000); void * const p = realloc(loc->indata->datavec, sizeof(double) * loc->indata->vecallocated); if (p == NULL) { diff --git a/src/xspice/icm/analog/pwl/cfunc.mod b/src/xspice/icm/analog/pwl/cfunc.mod index ffb53d8e4..94f56da60 100644 --- a/src/xspice/icm/analog/pwl/cfunc.mod +++ b/src/xspice/icm/analog/pwl/cfunc.mod @@ -270,8 +270,10 @@ void cm_pwl(ARGS) /* structure holding parms, double lower_slope; /* slope of the lower segment */ double upper_slope; /* slope of the upper segment */ double x_input; /* input */ - double out; /* output */ - double dout_din; /* partial derivative of the output wrt input */ + double out = 0.0; /* output + * Init to 0 to suppress compiler warning */ + double dout_din = 0.0; /* partial derivative of the output wrt input. + * Init to 0 to suppress compiler warning */ double threshold_lower; /* value below which the output begins smoothing */ double threshold_upper; /* value above which the output begins smoothing */ double test1; /* debug testing value */ diff --git a/src/xspice/icm/digital/d_jkff/cfunc.mod b/src/xspice/icm/digital/d_jkff/cfunc.mod index 26678c20e..2341b8f87 100644 --- a/src/xspice/icm/digital/d_jkff/cfunc.mod +++ b/src/xspice/icm/digital/d_jkff/cfunc.mod @@ -187,7 +187,7 @@ static Digital_State_t cm_eval_jk_result(Digital_State_t j_input, Digital_State_t k_input, Digital_State_t old_output) { - Digital_State_t output; /* returned output value */ + Digital_State_t output = UNKNOWN; /* returned output value */ switch (j_input) { @@ -228,7 +228,6 @@ static Digital_State_t cm_eval_jk_result(Digital_State_t j_input, } return output; - } /*============================================================================== diff --git a/src/xspice/icm/digital/d_tff/cfunc.mod b/src/xspice/icm/digital/d_tff/cfunc.mod index 5d09568e0..ec4cc84b0 100644 --- a/src/xspice/icm/digital/d_tff/cfunc.mod +++ b/src/xspice/icm/digital/d_tff/cfunc.mod @@ -580,6 +580,7 @@ void cm_d_tff(ARGS) temp = *out_old; break; case UNKNOWN: + default: temp = UNKNOWN; break; } diff --git a/src/xspice/icm/dlmain.c b/src/xspice/icm/dlmain.c index b6af6324c..8f8d759f5 100644 --- a/src/xspice/icm/dlmain.c +++ b/src/xspice/icm/dlmain.c @@ -41,8 +41,9 @@ const Evt_Udn_Info_t * const cmEVTudns[] = { const int cmEVTudnCNT = sizeof(cmEVTudns) / sizeof(Evt_Udn_Info_t *) - 1; -// Pointer to core info structure containing pointers to core functions. -struct coreInfo_t *coreitf; +/* Instantiation of pointer to core info structure containing pointers + * to core functions. */ +struct coreInfo_t *coreitf = (struct coreInfo_t *) NULL; ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// diff --git a/src/xspice/icm/table/mada/alloc.c b/src/xspice/icm/table/mada/alloc.c index b45d611aa..c3e91a218 100644 --- a/src/xspice/icm/table/mada/alloc.c +++ b/src/xspice/icm/table/mada/alloc.c @@ -41,9 +41,9 @@ sf_alloc(int n /* number of elements */, /* Use calloc so that any internal allocations will be set to NULL to * facilitate error recovery */ - if ((ptr = calloc(n, size)) == NULL) { + if ((ptr = calloc((size_t) n, size)) == NULL) { cm_message_printf("%s: cannot allocate %zd bytes : ", - __FILE__, n * size); + __FILE__, (size_t) n * size); return NULL; } diff --git a/src/xspice/icm/table/support/interp.c b/src/xspice/icm/table/support/interp.c index c3c5d2327..fa9f0b1e8 100644 --- a/src/xspice/icm/table/support/interp.c +++ b/src/xspice/icm/table/support/interp.c @@ -4,6 +4,8 @@ #include #include +#include "interp.h" + /*********************/ /* 3d geometry types */ /*********************/ diff --git a/src/xspice/icm/table/support/interp.h b/src/xspice/icm/table/support/interp.h new file mode 100644 index 000000000..dbbd2be42 --- /dev/null +++ b/src/xspice/icm/table/support/interp.h @@ -0,0 +1,8 @@ +#ifndef interp_h_included +#define interp_h_included +double BilinearInterpolation(double x, double y, + int xind, int yind, double **td); +double TrilinearInterpolation(double x, double y, double z, + int xind, int yind, int zind, double ***td); +int findCrossOver(double arr[], int n, double x); +#endif /* include guard */ diff --git a/src/xspice/icm/table/table2D/cfunc.mod b/src/xspice/icm/table/table2D/cfunc.mod index 2f4e91c8c..d7973a480 100644 --- a/src/xspice/icm/table/table2D/cfunc.mod +++ b/src/xspice/icm/table/table2D/cfunc.mod @@ -72,8 +72,9 @@ NON-STANDARD FEATURES #include #include -#include "support/gettokens.h" #include "mada/eno2.h" +#include "support/gettokens.h" +#include "support/interp.h" typedef struct { int ix; /* size of array in x */ @@ -105,10 +106,7 @@ typedef struct { /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ -double BilinearInterpolation(double x, double y, - int xind, int yind, double **td); static void cm_table2D_callback(ARGS, Mif_Callback_Reason_t reason); -extern int findCrossOver(double arr[], int n, double x); static void free_local_data(Table2_Data_t *loc); static inline double get_local_diff(int n, double *col, int ind); static Table2_Data_t *init_local_data(const char *filename, int interporder); diff --git a/src/xspice/icm/table/table3D/cfunc.mod b/src/xspice/icm/table/table3D/cfunc.mod index 411cc8fd8..8c6da7af6 100644 --- a/src/xspice/icm/table/table3D/cfunc.mod +++ b/src/xspice/icm/table/table3D/cfunc.mod @@ -73,6 +73,7 @@ NON-STANDARD FEATURES #include #include "support/gettokens.h" +#include "support/interp.h" #include "mada/eno2.h" #include "mada/eno3.h" @@ -108,10 +109,7 @@ typedef struct { /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ -extern double TrilinearInterpolation(double x, double y, double z, - int xind, int yind, int zind, double ***td); static void cm_table3D_callback(ARGS, Mif_Callback_Reason_t reason); -extern int findCrossOver(double arr[], int n, double x); static void free_local_data(Table3_Data_t *loc); static inline double get_local_diff(int n, double *col, int ind); diff --git a/src/xspice/icm/xtraevt/int/udnfunc.c b/src/xspice/icm/xtraevt/int/udnfunc.c index f4cf67878..2a3fa2899 100644 --- a/src/xspice/icm/xtraevt/int/udnfunc.c +++ b/src/xspice/icm/xtraevt/int/udnfunc.c @@ -40,13 +40,12 @@ NON-STANDARD FEATURES ============================================================================*/ #include + + #include "ngspice/cm.h" - #include "ngspice/evtudn.h" +#include "ngspice/memory.h" -void *tmalloc(size_t); - -#define TMALLOC(t,n) (t*) tmalloc(sizeof(t) * (size_t)(n)) /* macro to ignore unused variables and parameters */ #define NG_IGNORE(x) (void)x diff --git a/src/xspice/icm/xtraevt/real/udnfunc.c b/src/xspice/icm/xtraevt/real/udnfunc.c index df8d040a1..b9f5f2250 100644 --- a/src/xspice/icm/xtraevt/real/udnfunc.c +++ b/src/xspice/icm/xtraevt/real/udnfunc.c @@ -43,10 +43,9 @@ NON-STANDARD FEATURES #include "ngspice/cm.h" #include "ngspice/evtudn.h" +#include "ngspice/memory.h" -void *tmalloc(size_t); -#define TMALLOC(t,n) (t*) tmalloc(sizeof(t) * (size_t)(n)) /* macro to ignore unused variables and parameters */ #define NG_IGNORE(x) (void)x diff --git a/visualc/vngspice.sln b/visualc/vngspice.sln index 6b5d138e5..260d55371 100644 --- a/visualc/vngspice.sln +++ b/visualc/vngspice.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 14 -VisualStudioVersion = 14.0.23107.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vngspice", "vngspice.vcxproj", "{83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}" ProjectSection(ProjectDependencies) = postProject @@ -86,24 +86,24 @@ Global {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.ReleaseOMP|x64.Build.0 = ReleaseOMP|x64 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.ReleaseOMP|x86.ActiveCfg = ReleaseOMP|Win32 {83E315C7-EDD3-4F6B-AF28-87A92A4FA49A}.ReleaseOMP|x86.Build.0 = ReleaseOMP|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_debug|x64.ActiveCfg = Debug|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_debug|x64.Build.0 = Debug|Win32 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_debug|x64.ActiveCfg = Debug|x64 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_debug|x64.Build.0 = Debug|x64 {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_debug|x86.ActiveCfg = Debug|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_debug|x86.Build.0 = Debug|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release_omp|x64.ActiveCfg = Release|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release_omp|x64.Build.0 = Release|Win32 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release_omp|x64.ActiveCfg = Release|x64 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release_omp|x64.Build.0 = Release|x64 {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release_omp|x86.ActiveCfg = Release|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release_omp|x86.Build.0 = Release|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release|x64.ActiveCfg = Release|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release|x64.Build.0 = Release|Win32 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release|x64.ActiveCfg = Release|x64 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release|x64.Build.0 = Release|x64 {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release|x86.ActiveCfg = Release|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.console_release|x86.Build.0 = Release|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.Debug|x64.ActiveCfg = Debug|x64 {7C865696-FA10-43AE-A20B-22AE72A165E2}.Debug|x64.Build.0 = Debug|x64 {7C865696-FA10-43AE-A20B-22AE72A165E2}.Debug|x86.ActiveCfg = Debug|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.Debug|x86.Build.0 = Debug|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.Release|x64.ActiveCfg = Release|Win32 - {7C865696-FA10-43AE-A20B-22AE72A165E2}.Release|x64.Build.0 = Release|Win32 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.Release|x64.ActiveCfg = Release|x64 + {7C865696-FA10-43AE-A20B-22AE72A165E2}.Release|x64.Build.0 = Release|x64 {7C865696-FA10-43AE-A20B-22AE72A165E2}.Release|x86.ActiveCfg = Release|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.Release|x86.Build.0 = Release|Win32 {7C865696-FA10-43AE-A20B-22AE72A165E2}.ReleaseOMP|x64.ActiveCfg = Release|x64 diff --git a/visualc/xspice/table.vcxproj b/visualc/xspice/table.vcxproj index d65d404c4..c9adf1c32 100644 --- a/visualc/xspice/table.vcxproj +++ b/visualc/xspice/table.vcxproj @@ -223,8 +223,10 @@ + + - + \ No newline at end of file