Fixed some issues found with Coverity.

This commit is contained in:
Matthias Koefferlein 2018-02-21 00:21:19 +01:00
parent 6052a04429
commit 2f46f0d1c6
22 changed files with 153 additions and 116 deletions

View File

@ -1035,7 +1035,7 @@ public:
value_type operator* () const
{
return value_type (*(dynamic_cast<const ant::Object *> (m_iter->first->ptr ())), m_services[m_service]->view ());
return value_type (*(static_cast<const ant::Object *> (m_iter->first->ptr ())), m_services[m_service]->view ());
}
private:

View File

@ -110,6 +110,18 @@ OASISReader::OASISReader (tl::InputStream &s)
{
m_progress.set_format (tl::to_string (QObject::tr ("%.0f MB")));
m_progress.set_unit (1024 * 1024);
m_first_cellname = 0;
m_first_propname = 0;
m_first_propstring = 0;
m_first_textstring = 0;
m_first_layername = 0;
m_in_table = NotInTable;
m_table_cellname = 0;
m_table_propname = 0;
m_table_propstring = 0;
m_table_textstring = 0;
m_table_layername = 0;
m_table_start = 0;
}
OASISReader::~OASISReader ()
@ -197,6 +209,16 @@ OASISReader::get_long ()
}
}
inline unsigned long
OASISReader::get_ulong_for_divider ()
{
unsigned long l = get_ulong ();
if (l == 0) {
error (tl::to_string (QObject::tr ("Divider must not be zero")));
}
return l;
}
inline unsigned long
OASISReader::get_ulong ()
{
@ -295,21 +317,21 @@ OASISReader::get_real ()
} else if (t == 2) {
return 1.0 / double (get_ulong ());
return 1.0 / double (get_ulong_for_divider ());
} else if (t == 3) {
return -1.0 / double (get_ulong ());
return -1.0 / double (get_ulong_for_divider ());
} else if (t == 4) {
double d = double (get_ulong ());
return d / double (get_ulong ());
return d / double (get_ulong_for_divider ());
} else if (t == 5) {
double d = double (get_ulong ());
return -d / double (get_ulong ());
return -d / double (get_ulong_for_divider ());
} else if (t == 6) {

View File

@ -318,6 +318,7 @@ private:
unsigned long long get_ulong_long ();
long get_long ();
unsigned long get_ulong ();
unsigned long get_ulong_for_divider ();
int get_int ();
unsigned int get_uint ();

View File

@ -276,6 +276,8 @@ RecursiveShapeIterator::init ()
m_shape_inv_prop_sel = false;
m_inst_quad_id = 0;
m_shape_quad_id = 0;
mp_cell = 0;
m_current_layer = 0;
}
void

View File

@ -58,6 +58,7 @@ struct A : public db::Object
void redo (db::Op *op) throw ()
{
AO *aop = dynamic_cast<AO *> (op);
tl_assert (aop != 0);
x += aop->d;
}
@ -162,6 +163,7 @@ struct B : public db::Object
void redo (db::Op *op) throw ()
{
BO *bop = dynamic_cast<BO *> (op);
tl_assert (bop != 0);
x += bop->d;
}

View File

@ -1092,7 +1092,7 @@ Net::Net ()
}
Net::Net (const NetTracer &tracer, const db::ICplxTrans &trans, const db::Layout &layout, db::cell_index_type cell_index, const std::string &layout_filename, const std::string &layout_name, const NetTracerData &data)
: m_name (tracer.name ()), m_incomplete (tracer.incomplete ())
: m_name (tracer.name ()), m_incomplete (tracer.incomplete ()), m_trace_path (false)
{
m_dbu = layout.dbu ();
m_top_cell_name = layout.cell_name (cell_index);

View File

@ -607,11 +607,30 @@ RS274XMacroAperture::do_produce_flash ()
}
}
void
RS274XMacroAperture::read_exposure (tl::Extractor &ex, bool &clear, bool &clear_set)
{
int pol = int (floor (read_expr (ex) + 0.5));
if (pol == 0) {
clear = true;
} else if (pol == 1) {
clear = false;
} else if (pol == 2) {
clear = !clear_set || !clear;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid exposure code '%d'")), pol);
}
clear_set = true;
}
void
RS274XMacroAperture::do_produce_flash_internal ()
{
tl::Extractor ex (m_def.c_str ());
bool clear = false;
bool clear_set = false;
while (! ex.at_end ()) {
@ -640,18 +659,7 @@ RS274XMacroAperture::do_produce_flash_internal ()
if (code == 1) {
ex.expect (",");
int pol = (read_expr (ex) > 0.5);
if (pol == 0) {
clear = true;
} else if (pol == 1) {
clear = false;
} else if (pol == 2) {
clear = !clear;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid exposure code '%d'")), pol);
}
read_exposure (ex, clear, clear_set);
ex.expect (",");
double d = read_expr (ex, true);
ex.expect (",");
@ -670,18 +678,7 @@ RS274XMacroAperture::do_produce_flash_internal ()
} else if (code == 2 || code == 20) {
ex.expect (",");
int pol = (read_expr (ex) > 0.5);
if (pol == 0) {
clear = true;
} else if (pol == 1) {
clear = false;
} else if (pol == 2) {
clear = !clear;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid exposure code '%d'")), pol);
}
read_exposure (ex, clear, clear_set);
ex.expect (",");
double w = read_expr (ex, true);
ex.expect (",");
@ -723,18 +720,7 @@ RS274XMacroAperture::do_produce_flash_internal ()
} else if (code == 21 || code == 22) {
ex.expect (",");
int pol = (read_expr (ex) > 0.5);
if (pol == 0) {
clear = true;
} else if (pol == 1) {
clear = false;
} else if (pol == 2) {
clear = !clear;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid exposure code '%d'")), pol);
}
read_exposure (ex, clear, clear_set);
ex.expect (",");
double w = read_expr (ex, true);
ex.expect (",");
@ -766,18 +752,7 @@ RS274XMacroAperture::do_produce_flash_internal ()
} else if (code == 4) {
ex.expect (",");
int pol = (read_expr (ex) > 0.5);
if (pol == 0) {
clear = true;
} else if (pol == 1) {
clear = false;
} else if (pol == 2) {
clear = !clear;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid exposure code '%d'")), pol);
}
read_exposure (ex, clear, clear_set);
ex.expect (",");
int n = int (read_expr (ex) + 0.5);
if (n < 1) {
@ -854,18 +829,7 @@ RS274XMacroAperture::do_produce_flash_internal ()
} else if (code == 5) {
ex.expect (",");
int pol = (read_expr (ex) > 0.5);
if (pol == 0) {
clear = true;
} else if (pol == 1) {
clear = false;
} else if (pol == 2) {
clear = !clear;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("Invalid exposure code '%d'")), pol);
}
read_exposure (ex, clear, clear_set);
ex.expect (",");
int n = int (read_expr (ex) + 0.5);
if (n < 3) {

View File

@ -168,6 +168,7 @@ private:
double read_atom (tl::Extractor &ex);
double read_dot_expr (tl::Extractor &ex);
double read_expr (tl::Extractor &ex, bool length = false);
void read_exposure (tl::Extractor &ex, bool &clear, bool &clear_set);
void do_produce_flash_internal ();
};

View File

@ -524,7 +524,6 @@ private:
ArgType m_ret_type;
bool m_const : 1;
bool m_static : 1;
bool m_is_predicate : 1;
bool m_protected : 1;
unsigned int m_argsize;
std::vector<MethodSynonym> m_method_synonyms;

View File

@ -697,12 +697,14 @@ static size_t make_id ()
Object::Object ()
: m_trans (1.0), mp_data (0), m_id (make_id ()), m_min_value (0.0), m_max_value (1.0), m_min_value_set (false), m_max_value_set (false), m_visible (true), m_z_position (0)
{
m_updates_enabled = false;
mp_pixel_data = 0;
}
Object::Object (size_t w, size_t h, const db::DCplxTrans &trans, bool color)
: m_trans (trans), m_id (make_id ()), m_min_value (0.0), m_max_value (1.0), m_min_value_set (false), m_max_value_set (false), m_visible (true), m_z_position (0)
{
m_updates_enabled = false;
mp_pixel_data = 0;
mp_data = new DataHeader (w, h, color, false);

View File

@ -211,10 +211,12 @@ ProgressReporter::set_visible (bool vis)
// actual operation
tl::DeferredMethodScheduler::enable (!vis);
if (!vis) {
mp_pb->progress_remove_widget ();
} else if (mp_pb->progress_wants_widget () && mp_objects.front ()) {
mp_pb->progress_add_widget (mp_objects.front ()->progress_widget ());
if (mp_pb) {
if (!vis) {
mp_pb->progress_remove_widget ();
} else if (mp_pb->progress_wants_widget () && mp_objects.front ()) {
mp_pb->progress_add_widget (mp_objects.front ()->progress_widget ());
}
}
m_pw_visible = vis;

View File

@ -259,7 +259,7 @@ SaltGrainPropertiesDialog::dependency_changed (QTreeWidgetItem *item, int column
m_update_enabled = false;
std::string name = tl::to_string (item->data (0, Qt::UserRole).toString ().simplified ());
SaltGrain *g = mp_salt->grain_by_name (name);
SaltGrain *g = mp_salt ? mp_salt->grain_by_name (name) : 0;
if (column == 0 && mp_salt) {

View File

@ -45,7 +45,7 @@ static lay::Technology *create_technology (const std::string &name)
{
lay::Technology *tech = new lay::Technology ();
tech->set_name (name);
lay::Technologies::instance ()->add (tech);
lay::Technologies::instance ()->add_new (tech);
return tech;
}

View File

@ -88,11 +88,13 @@ save_dialog_state (QWidget *w)
}
for (QList<QObject *>::const_iterator c = w->children ().begin (); c != w->children ().end (); ++c) {
if (dynamic_cast <QWidget *> (*c)) {
std::string cs = save_dialog_state (dynamic_cast <QWidget *> (*c));
if (! cs.empty ()) {
s += cs;
if (w) {
for (QList<QObject *>::const_iterator c = w->children ().begin (); c != w->children ().end (); ++c) {
if (dynamic_cast <QWidget *> (*c)) {
std::string cs = save_dialog_state (dynamic_cast <QWidget *> (*c));
if (! cs.empty ()) {
s += cs;
}
}
}
}

View File

@ -45,6 +45,8 @@ Technologies::Technologies ()
Technologies::Technologies (const Technologies &other)
: tl::Object ()
{
m_changed = false;
m_in_update = false;
operator= (other);
}
@ -115,19 +117,30 @@ Technologies::load_from_xml (const std::string &s)
}
void
Technologies::add (Technology *technology)
Technologies::add_tech (Technology *tech, bool replace_same)
{
for (tl::stable_vector<Technology>::iterator t = m_technologies.begin (); technology && t != m_technologies.end (); ++t) {
if (t->name () == technology->name ()) {
*t = *technology;
delete technology;
technology = 0;
if (! tech) {
return;
}
std::auto_ptr<Technology> tech_ptr (tech);
Technology *t = 0;
for (tl::stable_vector<Technology>::iterator i = m_technologies.begin (); !t && i != m_technologies.end (); ++i) {
if (i->name () == tech->name ()) {
t = i.operator-> ();
}
}
if (technology) {
m_technologies.push_back (technology);
technology->technology_changed_with_sender_event.add (this, &Technologies::technology_changed);
if (t) {
if (replace_same) {
*t = *tech;
} else {
throw tl::Exception (tl::to_string (QObject::tr ("A technology with this name already exists: %1").arg (tl::to_qstring (tech->name ()))));
}
} else {
m_technologies.push_back (tech_ptr.release ());
tech->technology_changed_with_sender_event.add (this, &Technologies::technology_changed);
}
technologies_changed ();
@ -218,6 +231,7 @@ Technologies::technology_by_name (const std::string &name)
}
}
tl_assert (! m_technologies.empty ());
return &*m_technologies.begin ();
}

View File

@ -126,7 +126,22 @@ public:
* The container becomes owner of the technology object.
* Replaces a technology with the name of the given technology.
*/
void add (Technology *technology);
void add (Technology *technology)
{
add_tech (technology, true /*replace*/);
}
/**
* @brief Adds a technology with a new name
*
* Like \add, but throws an exception if a technology with this name
* already exists. Takes over ownership over the technology object.
* The technology object is discarded if an exception is thrown.
*/
void add_new (Technology *technology)
{
add_tech (technology, false /*throws exception on same name*/);
}
/**
* @brief Remove a technology with the given name from the setup
@ -233,6 +248,8 @@ private:
tl::stable_vector<Technology> m_technologies;
bool m_changed;
bool m_in_update;
void add_tech (Technology *technology, bool replace_same);
};
/**

View File

@ -915,26 +915,28 @@ void Macro::install_doc () const
if (cls == 0) {
tl::error << tl::to_string (QObject::tr ("Reading class doc from ")) << path () << ": " << tl::to_string (QObject::tr ("@method without preceeding @class"));
}
} else {
std::string n;
ex.read_word_or_quoted (n);
std::string n;
ex.read_word_or_quoted (n);
std::string doc;
while (++i < lines.size ()) {
std::string l = tl::trim (lines [i]);
if (l.find ("@method") == 0 || l.find ("@static_method") == 0) {
break;
std::string doc;
while (++i < lines.size ()) {
std::string l = tl::trim (lines [i]);
if (l.find ("@method") == 0 || l.find ("@static_method") == 0) {
break;
}
if (! doc.empty ()) {
doc += "\n";
}
doc += lines [i];
}
if (! doc.empty ()) {
doc += "\n";
}
doc += lines [i];
}
--i;
--i;
ExternalMethod *meth = new ExternalMethod (n, doc, false, st);
cls->add_method (meth);
ExternalMethod *meth = new ExternalMethod (n, doc, false, st);
cls->add_method (meth);
}
}

View File

@ -1945,7 +1945,11 @@ property_setter_impl (int mid, PyObject *self, PyObject *value)
if (meth->is_signal ()) {
if (PyObject_IsInstance (value, (PyObject *) PYASignal::cls)) {
if (!p) {
// TODO: Static signals?
} else if (PyObject_IsInstance (value, (PyObject *) PYASignal::cls)) {
// assigning a signal to a signal works if it applies to the same handler -
// this simplifies the implementation of += and -=.

View File

@ -495,7 +495,7 @@ public:
bool compare (const ValueBase *other) const
{
return m_value < dynamic_cast<const Value<C> *> (other)->m_value;
return m_value < static_cast<const Value<C> *> (other)->m_value;
}
std::string to_string () const;

View File

@ -213,7 +213,7 @@ public:
++lb0;
}
--lb;
if (lb != m_index_map.end () && i2 < lb->first.second) {
if (i2 < lb->first.second) {
// the last one is overlapping above i2: cut it
lb->first.first = i2;
} else {

View File

@ -424,17 +424,20 @@ JobBase::schedule (Task *task)
{
m_lock.lock ();
// Don't allow tasks to be scheduled while stopping or exiting (waiting for m_queue_empty_condition)
if (m_stopping) {
m_lock.unlock ();
throw TaskTerminatedException ();
}
// Add the task to the task queue
m_task_list.put (task);
// Don't allow tasks to be scheduled while stopping or exiting (waiting for m_queue_empty_condition)
delete task;
} else {
// Add the task to the task queue
m_task_list.put (task);
if (m_running) {
m_task_available_condition.wakeAll ();
}
if (m_running) {
m_task_available_condition.wakeAll ();
}
m_lock.unlock ();

View File

@ -1298,7 +1298,7 @@ Variant::can_convert_to_long () const
case t_double:
return m_var.m_double <= std::numeric_limits<long>::max () && m_var.m_double >= std::numeric_limits<long>::min ();
case t_float:
return m_var.m_float <= std::numeric_limits<long>::max () && m_var.m_float >= std::numeric_limits<long>::min ();
return m_var.m_float <= float (std::numeric_limits<long>::max ()) && m_var.m_float >= float (std::numeric_limits<long>::min ());
#if defined(HAVE_64BIT_COORD)
case t_int128:
return m_var.m_int128 <= __int128 (std::numeric_limits<long>::max ()) && m_var.m_int128 >= __int128 (std::numeric_limits<long>::min ());