Skip to content

Commit

Permalink
Add more guards in Resource* and Device Access (#7877)
Browse files Browse the repository at this point in the history
Part of hunting down a SEGV.
  • Loading branch information
manup authored Aug 9, 2024
1 parent d353f92 commit 88c0d9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 19 additions & 8 deletions device_access_fn.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 dresden elektronik ingenieurtechnik gmbh.
* Copyright (c) 2021-2024 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
Expand All @@ -9,6 +9,7 @@
*/

#include <QTimeZone>
#include "deconz/u_assert.h"
#include "device_access_fn.h"
#include "device_descriptions.h"
#include "device_js/device_js.h"
Expand Down Expand Up @@ -280,15 +281,25 @@ quint8 resolveAutoEndpoint(const Resource *r)
{
quint8 result = AutoEndpoint;

// hack to get endpoint. todo find better solution
const auto ls = r->item(RAttrUniqueId)->toString().split('-', SKIP_EMPTY_PARTS);
if (ls.size() >= 2)
U_ASSERT(r);
if (r)
{
bool ok = false;
uint ep = ls[1].toUInt(&ok, 16);
if (ok && ep < BroadcastEndpoint)
const ResourceItem *itemUniqueId = r->item(RAttrUniqueId);

U_ASSERT(itemUniqueId);
if (itemUniqueId)
{
result = ep;
// hack to get endpoint. todo find better solution
const auto ls = itemUniqueId->toString().split('-', SKIP_EMPTY_PARTS);
if (ls.size() >= 2)
{
bool ok = false;
uint ep = ls[1].toUInt(&ok, 16);
if (ok && ep < BroadcastEndpoint)
{
result = ep;
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,8 @@ const QString &ResourceItem::toString() const
}
else if (m_rid->type == DataTypeTime)
{
if (m_num > 0)
U_ASSERT(m_str);
if (m_num > 0 && m_str)
{
QDateTime dt;

Expand Down

0 comments on commit 88c0d9a

Please sign in to comment.