aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorNick Dedekind <nicholas.dedekind@gmail.com>2013-10-14 15:00:44 +0100
committerNick Dedekind <nicholas.dedekind@gmail.com>2013-10-14 15:00:44 +0100
commite7bfaf15e2e064f0eb24b4655f8a98acae792b5b (patch)
treee73643a8738da9adc9058235f56a3c5380dc0f68 /libqmenumodel/src
parent867693af1b3453b4ec83591a4bffac889f9503c8 (diff)
downloadqmenumodel-e7bfaf15e2e064f0eb24b4655f8a98acae792b5b.tar.gz
qmenumodel-e7bfaf15e2e064f0eb24b4655f8a98acae792b5b.tar.bz2
qmenumodel-e7bfaf15e2e064f0eb24b4655f8a98acae792b5b.zip
Added iterator/item pointer checks
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp57
1 files changed, 49 insertions, 8 deletions
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp
index 71358c4..cceed9e 100644
--- a/libqmenumodel/src/unitymenumodel.cpp
+++ b/libqmenumodel/src/unitymenumodel.cpp
@@ -395,9 +395,18 @@ static QString iconUri(GIcon *icon)
QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
{
+ GSequenceIter *it;
GtkMenuTrackerItem *item;
- item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index.row()));
+ it = g_sequence_get_iter_at_pos (priv->items, index.row());
+ if (!it || g_sequence_iter_is_end (it)) {
+ return QVariant();
+ }
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (it);
+ if (!item) {
+ return QVariant();
+ }
switch (role) {
case LabelRole:
@@ -497,12 +506,14 @@ QObject * UnityMenuModel::submenu(int position, QQmlComponent* actionStateParser
UnityMenuModel *model;
it = g_sequence_get_iter_at_pos (priv->items, position);
- if (g_sequence_iter_is_end (it))
+ if (!it || g_sequence_iter_is_end (it)) {
return NULL;
+ }
item = (GtkMenuTrackerItem *) g_sequence_get (it);
- if (!gtk_menu_tracker_item_get_has_submenu (item))
+ if (!item || !gtk_menu_tracker_item_get_has_submenu (item)) {
return NULL;
+ }
model = (UnityMenuModel *) g_object_get_qdata (G_OBJECT (item), unity_submenu_model_quark ());
if (model == NULL) {
@@ -603,10 +614,19 @@ static QString qtify_name(const char *name)
bool UnityMenuModel::loadExtendedAttributes(int position, const QVariantMap &schema)
{
+ GSequenceIter *it;
GtkMenuTrackerItem *item;
QVariantMap *extendedAttrs;
- item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, position));
+ it = g_sequence_get_iter_at_pos (priv->items, position);
+ if (!it || g_sequence_iter_is_end (it)) {
+ return false;
+ }
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (it);
+ if (!item) {
+ return false;
+ }
extendedAttrs = new QVariantMap;
@@ -647,9 +667,18 @@ QVariant UnityMenuModel::get(int row, const QByteArray &role)
void UnityMenuModel::activate(int index, const QVariant& parameter)
{
+ GSequenceIter *it;
GtkMenuTrackerItem *item;
- item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index));
+ it = g_sequence_get_iter_at_pos (priv->items, index);
+ if (!it || g_sequence_iter_is_end (it)) {
+ return;
+ }
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (it);
+ if (!item) {
+ return;
+ }
if (parameter.isValid()) {
gchar *action;
@@ -665,12 +694,20 @@ void UnityMenuModel::activate(int index, const QVariant& parameter)
void UnityMenuModel::changeState(int index, const QVariant& parameter)
{
+ GSequenceIter *it;
GtkMenuTrackerItem* item;
GVariant* data;
GVariant* current_state;
- item = (GtkMenuTrackerItem *) g_sequence_get (g_sequence_get_iter_at_pos (priv->items, index));
- if (!item) return;
+ it = g_sequence_get_iter_at_pos (priv->items, index);
+ if (!it || g_sequence_iter_is_end (it)) {
+ return;
+ }
+
+ item = (GtkMenuTrackerItem *) g_sequence_get (it);
+ if (!item) {
+ return;
+ }
current_state = gtk_menu_tracker_item_get_action_state (item);
if (current_state) {
@@ -794,11 +831,15 @@ char * UnityMenuModelPrivate::fullActionName(UnityMenuAction *action)
name = bytes.constData();
iter = g_sequence_get_iter_at_pos (this->items, action->index());
- if (!g_sequence_iter_is_end (iter)) {
+ if (iter && !g_sequence_iter_is_end (iter)) {
GtkMenuTrackerItem *item;
const gchar *action_namespace;
item = (GtkMenuTrackerItem *) g_sequence_get (iter);
+ if (!item) {
+ return g_strdup (name);
+ }
+
action_namespace = gtk_menu_tracker_item_get_action_namespace (item);
if (action_namespace != NULL)
return g_strjoin (".", action_namespace, name, NULL);