Skip to content

Commit fdbdaba

Browse files
author
ThomasZecha
committed
-The lookahead-pattern for differentiate the 3-/4-/5-node spice-bjt erroneously contains newline. This causes read a spice bjt-line don't stop at new line and detect a 5-node bjt instead of 3-node bjt as happen for AD822X.cir of Opamp_AC_Tran.zip from the issue 967. This is fixed and tested against AD822X.cir. The critical lines from AD822X.cir are included in the bjt.cir qucsconv_rf testing example. cherry-picked from 3c375fd: Fix build issues -fixed sprintf format buffer overflow warning: check_citi.cpp, check_mdl.cpp, check_spice.cpp -fixed signed compare/expression warning: check_mdl.cpp, circuit.cpp, hbsolver.cpp, e_trsolver.cpp, nasolver.cpp, spline.cpp, tmatrix.cpp, tvector.cpp -fixed clearing of non-trivial type via memset warning by static_cast: circuit.cpp, tmatrix.cpp -fixed int-in-bool-context warning: thyristor.cpp -fixed unnecessary parentheses warning: environment.cpp, equation.cpp, evaluate.cpp -fixed case fallthrough warning: equation.cpp -fixed unused parameter/variable warning: e_trsolver.cpp, real.cpp, qucs_action.cpp -fixed infinite recursion warning: real.cpp, real.h -fixed format type warning: module.cpp -fixed depracated copy warning by adding assignment operator: strlist.cpp, strlist.h -fixed misleading indentation warning: vector.cpp -fixed deprecated yacc/bison name-prefix directive warning: parse_spice.ypp, parse_vcd.ypp, parse_citi.ypp, parse_csv.ypp, parse_dataset.ypp, parse_mdl.ypp parse_mdl.ypp parse_netlist.ypp, parse_touchstone.ypp parse_zvr.ypp -fixed useless yacc/bison symbol definition: parse_vcd.ypp -fixed shift/reduce-conflicts (sr) and reduce/reduce-conflicts (rr) of the spice-parser build by parse_spice.ypp and scan_spice.lpp: -sr-conflicts solved by introducing token/rule precedence -rr-conflicts solved by introducing token lookahead's in the spice scanner -verification of equalness of generated output from both the converter before and after the code change done with spice input bjt.cir done -fixed shift/reduce-conflicts (sr) and reduce/reduce-conflicts (rr) of the csv-parser build by parse_csv.ypp and scan_csv.lpp: -sr/rr-conflicts solved by downsize and reorder grammatic rules -verification of equalness of generated output from both the converter before and after the code change done with csv input qucs_csv.csv done -removed useless scanner token definition and replaced misleading operator assocativity with precedence: parse_netlist.ypp -fixed shift/reduce-conflicts (sr) of the touchstone-parser build by parse_touchstone.ypp and scan_touchstonelpp: -sr conflicts solved by remove useless/redundant grammatic rules -verification of equalness of generated output from both the converter before and after the code change done with touchstone input R50C1pF.s1p done Signed-off-by: ThomasZecha <zecha@ihp-microelectronics.com>
1 parent b1072f1 commit fdbdaba

35 files changed

+297
-160
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ foreach(type ${ParserTypes})
9696
${BISON_EXECUTABLE}
9797
--defines=parse_${type}.hpp
9898
--output=parse_${type}.cpp
99+
-v
100+
-Wprecedence
99101
${bisonIn}
100102
DEPENDS ${bisonIn})
101103
# Create custom Flex

src/check_citi.cpp

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ static char * citi_get_package (struct citi_package_t * p) {
8989
}
9090

9191
/* Create a valid vector for the dataset. */
92-
static qucs::vector * citi_create_vector (struct citi_package_t * p, int i,
93-
char * n, char * type) {
92+
static qucs::vector * citi_create_vector (struct citi_package_t * p, int i, char * n, char * type) {
9493
qucs::vector * vec;
9594
vec = citi_get_vector (p, i); // fetch vector
9695
vec = new qucs::vector (*vec); // copy vector
@@ -195,8 +194,8 @@ int citi_check (void) {
195194
int cvar = citi_count_variables (p);
196195
if (cvec != cvar) {
197196
logprint (LOG_ERROR, "checker error, no. of vectors (%d) does not equal "
198-
"no. of variables (%d) in package `%s'\n", cvec, cvar,
199-
package);
197+
"no. of variables (%d) in package `%s'\n", cvec, cvar,
198+
package);
200199
errors++;
201200
break;
202201
}
@@ -213,50 +212,50 @@ int citi_check (void) {
213212
for (h = p->head; h != NULL; h = h->next) {
214213
qucs::vector * v;
215214
if (h->var != NULL) {
216-
char txt[256];
217-
if (h->i1 >= 0) {
218-
/* dependent variables */
219-
if (h->i2 >= 0) {
220-
sprintf (txt, "%s%s[%d,%d]", opack, h->var, h->i1, h->i2);
221-
v = citi_create_vector (p, n, txt, h->type);
222-
v->setDependencies (new strlist (deps));
223-
errors += citi_check_dep_length (v, deps, package);
224-
citi_result->addVariable (v);
225-
n++;
226-
} else {
227-
sprintf (txt, "%s%s[%d]", opack, h->var, h->i1);
228-
v = citi_create_vector (p, n, txt, h->type);
229-
v->setDependencies (new strlist (deps));
230-
errors += citi_check_dep_length (v, deps, package);
231-
citi_result->addVariable (v);
232-
n++;
233-
}
234-
} else if (h->n >= 0) {
235-
/* independent variable */
236-
sprintf (txt, "%s%s", opack, h->var);
237-
v = citi_create_vector (p, n, txt, h->type);
238-
deps.add (txt);
239-
if (!citi_result->findDependency (txt)) {
240-
/* add independent vectors only once */
241-
citi_result->addDependency (v);
242-
}
243-
n++;
244-
// check length of independent vector
245-
if (v->getSize () != h->n) {
246-
logprint (LOG_ERROR, "checker error, vector `%s' length (%d) "
247-
"does not equal defined length (%d) in package `%s'\n",
248-
h->var, v->getSize (), h->n, package);
249-
errors++;
250-
}
251-
} else {
252-
/* dependent variables, no indices */
253-
sprintf (txt, "%s%s", opack, h->var);
254-
v = citi_create_vector (p, n, txt, h->type);
255-
v->setDependencies (new strlist (deps));
256-
errors += citi_check_dep_length (v, deps, package);
257-
citi_result->addVariable (v);
258-
n++;
259-
}
215+
char txt[sizeof(opack) + 16];
216+
if (h->i1 >= 0) {
217+
/* dependent variables */
218+
if (h->i2 >= 0) {
219+
sprintf (txt, "%s%s[%d,%d]", opack, h->var, h->i1, h->i2);
220+
v = citi_create_vector (p, n, txt, h->type);
221+
v->setDependencies (new strlist (deps));
222+
errors += citi_check_dep_length (v, deps, package);
223+
citi_result->addVariable (v);
224+
n++;
225+
} else {
226+
sprintf (txt, "%s%s[%d]", opack, h->var, h->i1);
227+
v = citi_create_vector (p, n, txt, h->type);
228+
v->setDependencies (new strlist (deps));
229+
errors += citi_check_dep_length (v, deps, package);
230+
citi_result->addVariable (v);
231+
n++;
232+
}
233+
} else if (h->n >= 0) {
234+
/* independent variable */
235+
sprintf (txt, "%s%s", opack, h->var);
236+
v = citi_create_vector (p, n, txt, h->type);
237+
deps.add (txt);
238+
if (!citi_result->findDependency (txt)) {
239+
/* add independent vectors only once */
240+
citi_result->addDependency (v);
241+
}
242+
n++;
243+
// check length of independent vector
244+
if (v->getSize () != h->n) {
245+
logprint (LOG_ERROR, "checker error, vector `%s' length (%d) "
246+
"does not equal defined length (%d) in package `%s'\n",
247+
h->var, v->getSize (), h->n, package);
248+
errors++;
249+
}
250+
} else {
251+
/* dependent variables, no indices */
252+
sprintf (txt, "%s%s", opack, h->var);
253+
v = citi_create_vector (p, n, txt, h->type);
254+
v->setDependencies (new strlist (deps));
255+
errors += citi_check_dep_length (v, deps, package);
256+
citi_result->addVariable (v);
257+
n++;
258+
}
260259
}
261260
}
262261
}

src/check_mdl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ valuelist<int> * mdl_find_depdataset (struct mdl_link_t * link,
346346
else if (!strcmp (hyptab->name, "List Table")) {
347347
lstsweep * sw = new lstsweep ();
348348
sw->create (nof);
349-
char txt[16];
349+
char txt[32];
350350
for (int i = 0; i < nof; i++) {
351351
sprintf (txt, "Value %d", i + 1);
352352
val = mdl_helement_dvalue (link, hyptab->data, txt);
@@ -418,7 +418,7 @@ static void mdl_find_varlink (struct mdl_link_t * link, char * name,
418418
// Sorts a dependency list according to their sweep order.
419419
static strlist * mdl_sort_deps (valuelist<int> * d) {
420420
strlist * deps = new strlist ();
421-
for (int i = 0; i < d->size(); i++) {
421+
for (int i = 0; i < static_cast<int>(d->size()); i++) {
422422
for (auto &val: *d) {
423423
if (val.second == i + 1) {
424424
deps->append (val.first.c_str());

src/circuit.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,22 @@ void circuit::freeMatrixHB (void) {
229229
/* Allocates the HB-matrix memory. */
230230
void circuit::allocMatrixHB (void) {
231231
if (VectorQ) {
232-
memset (VectorQ, 0, size * sizeof (nr_complex_t));
232+
memset (static_cast<void*>(VectorQ), 0, size * sizeof (nr_complex_t));
233233
} else {
234234
VectorQ = new nr_complex_t[size];
235235
}
236236
if (MatrixQV) {
237-
memset (MatrixQV, 0, size * size * sizeof (nr_complex_t));
237+
memset (static_cast<void*>(MatrixQV), 0, size * size * sizeof (nr_complex_t));
238238
} else {
239239
MatrixQV = new nr_complex_t[size * size];
240240
}
241241
if (VectorCV) {
242-
memset (VectorCV, 0, size * sizeof (nr_complex_t));
242+
memset (static_cast<void*>(VectorCV), 0, size * sizeof (nr_complex_t));
243243
} else {
244244
VectorCV = new nr_complex_t[size];
245245
}
246246
if (VectorGV) {
247-
memset (VectorGV, 0, size * sizeof (nr_complex_t));
247+
memset (static_cast<void*>(VectorGV), 0, size * sizeof (nr_complex_t));
248248
} else {
249249
VectorGV = new nr_complex_t[size];
250250
}
@@ -253,7 +253,7 @@ void circuit::allocMatrixHB (void) {
253253
/* Allocates the S-parameter matrix memory. */
254254
void circuit::allocMatrixS (void) {
255255
if (MatrixS) {
256-
memset (MatrixS, 0, size * size * sizeof (nr_complex_t));
256+
memset (static_cast<void*>(MatrixS), 0, size * size * sizeof (nr_complex_t));
257257
} else {
258258
MatrixS = new nr_complex_t[size * size];
259259
}
@@ -654,8 +654,8 @@ void circuit::setMatrixS (matrix s) {
654654
circuit. */
655655
matrix circuit::getMatrixS (void) {
656656
matrix res (size);
657-
for(unsigned int i=0; i < size; ++i)
658-
for(unsigned int j=0; j < size; ++j)
657+
for(int i=0; i < size; ++i)
658+
for(int j=0; j < size; ++j)
659659
res(i,j) = MatrixS[i*size + j];
660660
return res;
661661
}
@@ -675,8 +675,8 @@ void circuit::setMatrixN (matrix n) {
675675
matrix of the circuit. */
676676
matrix circuit::getMatrixN (void) {
677677
matrix res (size);
678-
for(unsigned int i=0; i < size; ++i)
679-
for(unsigned int j=0; j < size; ++j)
678+
for(int i=0; i < size; ++i)
679+
for(int j=0; j < size; ++j)
680680
res(i,j) = MatrixN[i*size + j];
681681
return res;
682682
}
@@ -696,50 +696,50 @@ void circuit::setMatrixY (matrix y) {
696696
circuit. */
697697
matrix circuit::getMatrixY (void) {
698698
matrix res (size);
699-
for(unsigned int i=0; i < size; ++i)
700-
for(unsigned int j=0; j < size; ++j)
699+
for(int i=0; i < size; ++i)
700+
for(int j=0; j < size; ++j)
701701
res(i,j) = MatrixY[i*size + j];
702702
return res;
703703
}
704704

705705
// The function cleans up the B-MNA matrix entries.
706706
void circuit::clearB (void) {
707-
memset (MatrixB, 0, sizeof (nr_complex_t) * size * vsources);
707+
memset (static_cast<void*>(MatrixB), 0, sizeof (nr_complex_t) * size * vsources);
708708
}
709709

710710
// The function cleans up the C-MNA matrix entries.
711711
void circuit::clearC (void) {
712-
memset (MatrixC, 0, sizeof (nr_complex_t) * size * vsources);
712+
memset (static_cast<void*>(MatrixC), 0, sizeof (nr_complex_t) * size * vsources);
713713
}
714714

715715
// The function cleans up the D-MNA matrix entries.
716716
void circuit::clearD (void) {
717-
memset (MatrixD, 0, sizeof (nr_complex_t) * vsources * vsources);
717+
memset (static_cast<void*>(MatrixD), 0, sizeof (nr_complex_t) * vsources * vsources);
718718
}
719719

720720
// The function cleans up the E-MNA matrix entries.
721721
void circuit::clearE (void) {
722-
memset (VectorE, 0, sizeof (nr_complex_t) * vsources);
722+
memset (static_cast<void*>(VectorE), 0, sizeof (nr_complex_t) * vsources);
723723
}
724724

725725
// The function cleans up the J-MNA matrix entries.
726726
void circuit::clearJ (void) {
727-
memset (VectorJ, 0, sizeof (nr_complex_t) * vsources);
727+
memset (static_cast<void*>(VectorJ), 0, sizeof (nr_complex_t) * vsources);
728728
}
729729

730730
// The function cleans up the I-MNA matrix entries.
731731
void circuit::clearI (void) {
732-
memset (VectorI, 0, sizeof (nr_complex_t) * size);
732+
memset (static_cast<void*>(VectorI), 0, sizeof (nr_complex_t) * size);
733733
}
734734

735735
// The function cleans up the V-MNA matrix entries.
736736
void circuit::clearV (void) {
737-
memset (VectorV, 0, sizeof (nr_complex_t) * size);
737+
memset (static_cast<void*>(VectorV), 0, sizeof (nr_complex_t) * size);
738738
}
739739

740740
// The function cleans up the G-MNA matrix entries.
741741
void circuit::clearY (void) {
742-
memset (MatrixY, 0, sizeof (nr_complex_t) * size * size);
742+
memset (static_cast<void*>(MatrixY), 0, sizeof (nr_complex_t) * size * size);
743743
}
744744

745745
/* This function can be used by several components in order to place

src/components/devices/thyristor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void thyristor::calcTheModel (bool last) {
8585
isOn = Ud > Ud_bo;
8686

8787
nr_double_t Vak = real (getV (NODE_A1) - getV (NODE_A2));
88-
isOn *= (Vak > 0.0);
88+
isOn &= (Vak > 0.0);
8989

9090
if (Ud >= 80.0) {
9191
Id *= std::exp (80.0) * (1.0 + Ud - 80.0) - 1.0;

src/components/microstrip/bondwire.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ void bondwire::calcDC(void)
414414
}
415415
}
416416

417-
void bondwire::calcTR(nr_double_t t)
417+
void bondwire::calcTR()
418418
{
419419
calcDC();
420420
}

src/components/microstrip/bondwire.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class bondwire : public qucs::circuit
3939
void initTR (void);
4040
void calcDC (void);
4141
void calcAC (nr_double_t);
42-
void calcTR (nr_double_t);
42+
void calcTR ();
4343
void calcNoiseAC (nr_double_t);
4444
qucs::matrix calcMatrixY (nr_double_t);
4545
void saveCharacteristics (nr_double_t);

src/converter/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ foreach(type ${ParserTypes})
2626
${BISON_EXECUTABLE}
2727
--defines=parse_${type}.hpp
2828
--output=parse_${type}.cpp
29+
-v
30+
-Wce
31+
-Wprecedence
32+
-Wmidrule-value
2933
${bisonIn}
3034
DEPENDS ${bisonIn})
3135
# Create custom Flex
@@ -60,4 +64,4 @@ target_link_libraries(qucsconv_rf libqucsator ${CMAKE_DL_LIBS})
6064
#
6165
# Handle installation
6266
#
63-
install(TARGETS qucsconv_rf DESTINATION bin)
67+
install(TARGETS qucsconv_rf DESTINATION bin)

src/converter/check_spice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ static void spice_translate_nodes (struct definition_t * def, int pass) {
858858
node->node = strdup (t->node);
859859
else {
860860
// no node given, occurs in device descriptions
861-
char txt[16];
861+
char txt[17];
862862
sprintf (txt, "%s%d", "_node", n);
863863
node->node = strdup (txt);
864864
}

0 commit comments

Comments
 (0)