-
Notifications
You must be signed in to change notification settings - Fork 34
fix: prevent crash in SurfaceListModel::data when accessing childItem… #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: zorowk The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds defensive null checks in SurfaceListModel::data for the InitialSortOrderRole to avoid dereferencing incompletely initialized QQuickItem instances, and falls back to INT_MAX as the sort order for surfaces whose parent/container is not yet ready. Class diagram for updated SurfaceListModel::data null-check behaviorclassDiagram
class SurfaceListModel {
+data(index QModelIndex, role int) QVariant
+surfaces() QList~Surface*~
}
class Surface {
+parentItem() QQuickItem*
+container() QQuickItem*
}
class QQuickItem {
+childItems() QList~QQuickItem*~
}
class QModelIndex
class QVariant
SurfaceListModel --> Surface : uses
Surface --> QQuickItem : parentItem
Surface --> QQuickItem : container
QQuickItem --> QQuickItem : childItems
SurfaceListModel --> QModelIndex : parameter
SurfaceListModel --> QVariant : return type
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- Instead of returning the magic value INT_MAX in multiple places, consider defining a named constant (e.g. kUnreadySurfaceSortOrder) or using std::numeric_limits::max() to improve readability and type safety.
- Given that container->childItems().indexOf(surface) can theoretically return -1 even after your null checks, it may be safer to replace the Q_ASSERT with a conditional that also falls back to the default sort order rather than crashing in release builds.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Instead of returning the magic value INT_MAX in multiple places, consider defining a named constant (e.g. kUnreadySurfaceSortOrder) or using std::numeric_limits<int>::max() to improve readability and type safety.
- Given that container->childItems().indexOf(surface) can theoretically return -1 even after your null checks, it may be safer to replace the Q_ASSERT with a conditional that also falls back to the default sort order rather than crashing in release builds.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…s too early Add null checks for surface->parentItem() and container before calling container->childItems().indexOf(surface). This avoids dereferencing an incompletely initialized QQuickItem when a new surface is added to the model but has not yet been fully inserted into the scene graph. Returning INT_MAX as a fallback sort order places unready surfaces at the end of the list, ensuring stable behavior until the item is properly parented and polished. issue: linuxdeepin#659 comment: linuxdeepin#659 (comment)
…s too early
Add null checks for surface->parentItem() and container before calling container->childItems().indexOf(surface). This avoids dereferencing an incompletely initialized QQuickItem when a new surface is added to the model but has not yet been fully inserted into the scene graph.
Returning INT_MAX as a fallback sort order places unready surfaces at the end of the list, ensuring stable behavior until the item is properly parented and polished.
issue: #659
comment: #659 (comment)
Summary by Sourcery
Bug Fixes: