Commit 50ef037a authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

https://scan.coverity.com/projects/3327 Coverity fixes listed by CID :

268368, 268398 Division or modulo by float zero in umldoc.cpp
- In function UMLDoc::setResolution require `resolution' to be non null
  before calculating qApp->desktop()->logicalDpiX() / resolution.

268369 Dereference before null check in umlwidgets/enumwidget.cpp
- The issue refers to enumwidget.cpp but the cause is in
  umlwidgets/umlwidget.cpp:
- In function UMLWidget::setSize require m_scene to be non null before
  calling m_scene->snapComponentSizeToGrid().

268372 Out-of-bounds read in umllistview.cpp
- In function UMLListView::determineParentItem,
  - if `object' is null on entry then return null immediately;
  - require `guess' to be unequal to Uml::ModelType::N_MODELTYPES before
    accessing m_lv[guess].

268373 Out-of-bounds read in umldoc.cpp
- In function UMLDoc::findView require `mt' to be unequal to
  Uml::ModelType::N_MODELTYPES before accessing m_root[mt].

268389 Dereference after null check in docgenerators/
                                                docbookgeneratorjob.cpp
- In function xsltprocExternalEntityLoader require
  defaultEntityLoader to be non null before dereferencing as function.

268390, 268400 Structurally dead code in umlwidgets/widget_utils.cpp
- In functions defaultWidgetName, newTitle, newText, renameText remove
  `return QString()' at end of function.

268391 Out-of-bounds read in umldoc.cpp
- In function UMLDoc::loadDiagramsFromXMI1 while-loop handling of `tag'
  "diagram" or "UISDiagram", require `mt' to be unequal to
  Uml::ModelType::N_MODELTYPES before accessing m_root[mt] and calling
  addView(pView).

268394 Structurally dead code in model_utils.cpp
- In functions newTitle, newText, renameTitle, renameText remove
  `return QString()' at end of function.

268395 Missing break in switch in umlwidgets/associationline.cpp
- In function AssociationLine::reconstructSymbols switch statetement, at
  case Uml::AssociationType::Exception add comment
       // fall through
  as suggested in bug 442134 attachment 141364.

268396 Unchecked dynamic_cast in dotgenerator.cpp
- In function DotGenerator::createDotFile loop over scene->widgetList(),
  in nested loop over widget->childItems() require `w2' to be non null
  before dereferencing.

CCBUG: 340646
parent 7a8d1cfb
......@@ -91,7 +91,7 @@ static xmlParserInputPtr xsltprocExternalEntityLoader(const char *_URL, const ch
newURL = xmlStrdup((const xmlChar *) paths[i]);
newURL = xmlStrcat(newURL, (const xmlChar *) "/");
newURL = xmlStrcat(newURL, (const xmlChar *) lastsegment);
if (newURL != NULL) {
if (newURL != NULL && defaultEntityLoader != NULL) {
ret = defaultEntityLoader((const char *)newURL, ID, ctxt);
if (ret != NULL) {
if (warning != NULL)
......
......@@ -449,6 +449,10 @@ bool DotGenerator::createDotFile(UMLScene *scene, const QString &fileName, const
// add associations for child items
foreach(QGraphicsItem *item, widget->childItems()) {
UMLWidget *w2 = dynamic_cast<UMLWidget *>(item);
if (!w2) {
uWarning() << "child item of widget " << key << " is null";
continue;
}
QString type2 = dotType(w2);
QString id2 = fixID(Uml::ID::toString(w2->localID()));
QStringList params2;
......
......@@ -609,7 +609,6 @@ QString newTitle(UMLObject::ObjectType type)
uWarning() << "model_utils::newTitle unknown object type" << UMLObject::toString(type);
return i18n("New UML object");
}
return QString();
}
/**
......@@ -652,7 +651,6 @@ QString newText(UMLObject::ObjectType type)
uWarning() << "model_utils::newText unknown object type" << UMLObject::toString(type);
return i18n("Enter the name of the new UML object");
}
return QString();
}
/**
......@@ -695,7 +693,6 @@ QString renameTitle(UMLObject::ObjectType type)
uWarning() << "model_utils::renameTitle unknown object type" << UMLObject::toString(type);
return i18n("Rename UML object");
}
return QString();
}
/**
......@@ -738,7 +735,6 @@ QString renameText(UMLObject::ObjectType type)
uWarning() << "model_utils::renameText unknown object type" << UMLObject::toString(type);
return i18n("Enter the new name of the UML object");
}
return QString();
}
/**
......
......@@ -1022,6 +1022,11 @@ UMLView * UMLDoc::findView(Uml::DiagramType::Enum type, const QString &name,
bool searchAllScopes /* =false */) const
{
Uml::ModelType::Enum mt = Model_Utils::convert_DT_MT(type);
if (mt == Uml::ModelType::N_MODELTYPES) {
uWarning() << "UMLDoc::findView : Returning null because DiagramType "
<< type << " cannot be mapped to ModelType";
return nullptr;
}
return m_root[mt]->findView(type, name, searchAllScopes);
}
......@@ -2011,7 +2016,11 @@ QString UMLDoc::name() const
void UMLDoc::setResolution(qreal resolution)
{
m_resolution = resolution;
uDebug() << "screen dpi:" << qApp->desktop()->logicalDpiX() << "file dpi:" << resolution << "scale:" << qApp->desktop()->logicalDpiX() / resolution;
if (!qFuzzyIsNull(resolution)) {
uDebug() << "screen dpi:" << qApp->desktop()->logicalDpiX()
<< "file dpi:" << resolution
<< "scale:" << qApp->desktop()->logicalDpiX() / resolution;
}
}
/**
......@@ -2887,9 +2896,14 @@ bool UMLDoc::loadDiagramsFromXMI1(QDomNode & node)
// Put diagram in default predefined folder.
// @todo pass in the parent folder - it might be a user defined one.
Uml::ModelType::Enum mt = Model_Utils::convert_DT_MT(pView->umlScene()->type());
pView->umlScene()->setFolder(m_root[mt]);
pView->hide();
addView(pView);
if (mt != Uml::ModelType::N_MODELTYPES) {
pView->umlScene()->setFolder(m_root[mt]);
pView->hide();
addView(pView);
} else {
uWarning() << "cannot add " << tag << " because umlScene type "
<< pView->umlScene()->type() << " cannot be mapped to ModelType";
}
emit sigSetStatusbarProgress(++count);
qApp->processEvents(); // give UI events a chance
}
......
......@@ -879,6 +879,8 @@ void UMLListView::slotDiagramCreated(Uml::ID::Type id)
*/
UMLListViewItem* UMLListView::determineParentItem(UMLObject* object) const
{
if (object == nullptr)
return nullptr;
UMLListViewItem* parentItem = 0;
UMLPackage* pkg = 0;
UMLListViewItem* current = (UMLListViewItem*) currentItem();
......@@ -923,7 +925,11 @@ UMLListViewItem* UMLListView::determineParentItem(UMLObject* object) const
parentItem = m_datatypeFolder;
} else {
Uml::ModelType::Enum guess = Model_Utils::guessContainer(object);
parentItem = m_lv[guess];
if (guess != Uml::ModelType::N_MODELTYPES)
parentItem = m_lv[guess];
else
uWarning() << "UMLListView::determineParentItem: cannot guess container for object"
<< object->name();
}
break;
}
......
......@@ -522,6 +522,7 @@ void AssociationLine::reconstructSymbols()
switch( m_associationWidget->associationType() ) {
case Uml::AssociationType::Exception:
setLayout(Uml::LayoutType::Polyline);
// fall through
case Uml::AssociationType::State:
case Uml::AssociationType::Activity:
case Uml::AssociationType::UniAssociation:
......
......@@ -1780,13 +1780,13 @@ bool UMLWidget::getIgnoreSnapToGrid() const
/**
* Sets the size.
* If m_scene->snapComponentSizeToGrid() is true, then
* If m_scene->snapComponentSizeToGrid() is true then
* set the next larger size that snaps to the grid.
*/
void UMLWidget::setSize(qreal width, qreal height)
{
// snap to the next larger size that is a multiple of the grid
if (!m_ignoreSnapComponentSizeToGrid
if (!m_ignoreSnapComponentSizeToGrid && m_scene
&& m_scene->snapComponentSizeToGrid()) {
// integer divisions
int numX = width / m_scene->snapX();
......
......@@ -865,7 +865,6 @@ namespace Widget_Utils
return i18n("new widget");
break;
}
return QString();
}
/**
......@@ -911,7 +910,6 @@ namespace Widget_Utils
uWarning() << "unknown widget type:" << WidgetBase::toString(type);
return i18n("New widget");
}
return QString();
}
/**
......@@ -957,7 +955,6 @@ namespace Widget_Utils
uWarning() << "unknown widget type:" << WidgetBase::toString(type);
return i18n("Enter the name of the new widget:");
}
return QString();
}
/**
......@@ -1003,7 +1000,6 @@ namespace Widget_Utils
uWarning() << "unknown widget type:" << WidgetBase::toString(type);
return i18n("Rename widget");
}
return QString();
}
/**
......@@ -1049,6 +1045,5 @@ namespace Widget_Utils
uWarning() << "unknown widget type:" << WidgetBase::toString(type);
return i18n("Enter the new name of the widget:");
}
return QString();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment