[shotwell] Fix "possible null access" warnings



commit 3f5abb53d3d23b212db448af52b88d03cb51248c
Author: Jens Georg <mail jensge org>
Date:   Wed Feb 19 21:06:42 2020 +0100

    Fix "possible null access" warnings

 .../GalleryConnector.vala                          | 24 +++++++++++-----------
 src/Commands.vala                                  |  4 ++--
 src/MapWidget.vala                                 |  2 +-
 src/PhotoPage.vala                                 |  2 +-
 src/Printing.vala                                  |  4 ++--
 src/SearchFilter.vala                              | 10 +++++----
 src/camera/ImportPage.vala                         | 16 ++++++++-------
 src/data_imports/DataImportsUI.vala                |  8 ++++----
 src/dialogs/Preferences.vala                       |  6 +++---
 src/direct/DirectPhotoPage.vala                    |  5 +++--
 src/editing_tools/EditingTools.vala                |  2 +-
 src/photos/JfifSupport.vala                        |  8 +++++---
 src/searches/SavedSearchDialog.vala                |  2 +-
 13 files changed, 50 insertions(+), 43 deletions(-)
---
diff --git a/plugins/shotwell-publishing-extras/GalleryConnector.vala 
b/plugins/shotwell-publishing-extras/GalleryConnector.vala
index 9932862a..1d1418f1 100644
--- a/plugins/shotwell-publishing-extras/GalleryConnector.vala
+++ b/plugins/shotwell-publishing-extras/GalleryConnector.vala
@@ -1173,7 +1173,7 @@ public class GalleryPublisher : Spit.Publishing.Publisher, GLib.Object {
         if (session.is_authenticated())
             return;
 
-        key = (txn as KeyFetchTransaction).get_key();
+        key = ((KeyFetchTransaction)txn).get_key();
 
         if (key == null) error("key doesn\'t exist");
         else {
@@ -1242,7 +1242,7 @@ public class GalleryPublisher : Spit.Publishing.Publisher, GLib.Object {
         debug("EVENT: retrieving all album URLs.");
 
         string [] album_urls =
-            (txn as GetAlbumURLsTransaction).get_album_urls();
+            ((GetAlbumURLsTransaction)txn).get_album_urls();
 
         if (null == album_urls) {
 
@@ -1308,9 +1308,10 @@ public class GalleryPublisher : Spit.Publishing.Publisher, GLib.Object {
 
         debug("EVENT: user is attempting to populate the album list.");
 
+        var get_albums_txn = (GetAlbumsTransaction)txn;
+
         try {
-            new_albums =
-                (txn as GetAlbumsTransaction).get_albums();
+            new_albums = get_albums_txn.get_albums();
         } catch (Spit.Publishing.PublishingError err) {
             on_album_fetch_error(txn, err);
         }
@@ -1319,10 +1320,9 @@ public class GalleryPublisher : Spit.Publishing.Publisher, GLib.Object {
         for (int i = 0; i <= new_albums.length - 1; i++)
             albums += new_albums[i];
 
-        if ((txn as GetAlbumsTransaction).more_urls) {
-
-            do_fetch_albums((txn as GetAlbumsTransaction).album_urls,
-                (txn as GetAlbumsTransaction).urls_sent);
+        if (get_albums_txn.more_urls) {
+            do_fetch_albums(get_albums_txn.album_urls,
+                            get_albums_txn.urls_sent);
 
         }
         else {
@@ -1383,10 +1383,10 @@ public class GalleryPublisher : Spit.Publishing.Publisher, GLib.Object {
         if (!session.is_authenticated())
             return;
 
-        PublishingParameters new_params =
-            (txn as GalleryAlbumCreateTransaction).parameters;
-        new_params.album_path =
-            (txn as GalleryAlbumCreateTransaction).get_new_album_path();
+        var create_transaction = (GalleryAlbumCreateTransaction) txn;
+
+        PublishingParameters new_params = create_transaction.parameters;
+        new_params.album_path = create_transaction.get_new_album_path();
 
         debug("EVENT: user has created an album at \"%s\".",
             new_params.album_path);
diff --git a/src/Commands.vala b/src/Commands.vala
index 2c223256..9825b6de 100644
--- a/src/Commands.vala
+++ b/src/Commands.vala
@@ -1377,7 +1377,7 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand {
 
         // this should be replaced by a first function when we migrate to Gee's List
         foreach (DataView view in iter) {
-            prev_events.set(view.get_source() as Dateable, (view.get_source() as MediaSource).get_event());
+            prev_events.set(view.get_source() as Dateable, ((MediaSource) view.get_source()).get_event());
             
             if (new_time == null) {
                 new_time = ((Dateable) view.get_source()).get_exposure_time() +
@@ -1473,7 +1473,7 @@ public class AdjustDateTimePhotosCommand : MultipleDataSourceCommand {
             set_time(photo, photo.get_exposure_time() - (time_t) time_shift);
         }
         
-        (source as MediaSource).set_event(prev_events.get(source as Dateable));
+        ((MediaSource) source).set_event(prev_events.get(source as Dateable));
     }
 }
 
diff --git a/src/MapWidget.vala b/src/MapWidget.vala
index 3ee377b1..614c4870 100644
--- a/src/MapWidget.vala
+++ b/src/MapWidget.vala
@@ -510,7 +510,7 @@ private class MapWidget : Gtk.Bin {
             CheckerboardItem item = m.view as CheckerboardItem;
 
             if (!did_adjust_view && page is CheckerboardPage) {
-                (page as CheckerboardPage).scroll_to_item(item);
+                ((CheckerboardPage) page).scroll_to_item(item);
                 did_adjust_view = true;
             }
             item.brighten();
diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala
index 197a9ca8..7b5e758f 100644
--- a/src/PhotoPage.vala
+++ b/src/PhotoPage.vala
@@ -2464,7 +2464,7 @@ public class LibraryPhotoPage : EditingHostPage {
         base.add_actions (map);
 
         map.add_action_entries (entries, this);
-        (get_action ("ViewRatings") as GLib.SimpleAction).change_state (Config.Facade.get_instance 
().get_display_photo_ratings ());
+        ((GLib.SimpleAction) get_action ("ViewRatings")).change_state (Config.Facade.get_instance 
().get_display_photo_ratings ());
         var d = Config.Facade.get_instance().get_default_raw_developer();
         var action = new GLib.SimpleAction.stateful("RawDeveloper",
                 GLib.VariantType.STRING, d == RawDeveloper.SHOTWELL ? "Shotwell" : "Camera");
diff --git a/src/Printing.vala b/src/Printing.vala
index da46b08d..5fd893e0 100644
--- a/src/Printing.vala
+++ b/src/Printing.vala
@@ -683,7 +683,7 @@ public class CustomPrintTab : Gtk.Box {
     }
 
     private void set_print_titles_font(string fontname) {
-        (title_print_font as Gtk.FontChooser).set_font(fontname);
+        ((Gtk.FontChooser) title_print_font).set_font(fontname);
     }
 
 
@@ -696,7 +696,7 @@ public class CustomPrintTab : Gtk.Box {
     }
 
     private string get_print_titles_font() {
-        return (title_print_font as Gtk.FontChooser).get_font();
+        return ((Gtk.FontChooser) title_print_font).get_font();
     }
 
     public PrintJob get_source_job() {
diff --git a/src/SearchFilter.vala b/src/SearchFilter.vala
index e6bf0bc2..9a88cf2e 100644
--- a/src/SearchFilter.vala
+++ b/src/SearchFilter.vala
@@ -778,12 +778,13 @@ public class SearchFilterToolbar : Gtk.Revealer {
 
             switch (filter) {
                 case RatingFilter.REJECTED_OR_HIGHER:
-                    icon = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+                    var box = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
                     var image = new Gtk.Image.from_icon_name ("emblem-photos-symbolic", 
Gtk.IconSize.SMALL_TOOLBAR);
                     image.margin_end = 2;
-                    (icon as Gtk.Box).pack_start(image);
+                    box.pack_start(image);
                     image = new Gtk.Image.from_icon_name ("window-close-symbolic", 
Gtk.IconSize.SMALL_TOOLBAR);
-                    (icon as Gtk.Box).pack_start(image);
+                    box.pack_start(image);
+                    icon = box;
                     icon.show_all();
                 break;
                 
@@ -1018,7 +1019,8 @@ public class SearchFilterToolbar : Gtk.Revealer {
         }
 
         private SavedSearch get_search(Gtk.ListBoxRow row) {
-            DataButton button = (row.get_children().first().data as Gtk.Box).get_children().last().data as 
DataButton;
+            var box = (Gtk.Box) row.get_children().first().data;
+            DataButton button = box.get_children().last().data as DataButton;
             return button.search;
         }
 
diff --git a/src/camera/ImportPage.vala b/src/camera/ImportPage.vala
index b0cf107f..ab24df61 100644
--- a/src/camera/ImportPage.vala
+++ b/src/camera/ImportPage.vala
@@ -503,8 +503,9 @@ public class ImportPage : CheckerboardPage {
             assert(fulldir != null);
             filename = import_file.get_filename();
             filesize = import_file.get_filesize();
-            metadata = (import_file is PhotoImportSource) ?
-                (import_file as PhotoImportSource).get_metadata() : null;
+            var photo_import_source = import_file as PhotoImportSource;
+            metadata = (photo_import_source != null) ?
+                photo_import_source.get_metadata() : null;
             exposure_time = import_file.get_exposure_time();
         }
         
@@ -1590,12 +1591,13 @@ public class ImportPage : CheckerboardPage {
             debug("camera MD5 %s: exif=%s preview=%s", filename, exif_only_md5, preview_md5);
 #endif
 
-            if (import_source is VideoImportSource)
-                (import_source as VideoImportSource).update(preview);
+            var video_import_source = import_source as VideoImportSource;
+            if (video_import_source != null)
+                video_import_source.update(preview);
 
-            if (import_source is PhotoImportSource)
-                (import_source as PhotoImportSource).update(preview, preview_md5, metadata,
-                    exif_only_md5);
+            var photo_import_source = import_source as PhotoImportSource;
+            if (photo_import_source != null)
+                photo_import_source.update(preview, preview_md5, metadata, exif_only_md5);
             
             if (associated != null) {
                 try {
diff --git a/src/data_imports/DataImportsUI.vala b/src/data_imports/DataImportsUI.vala
index 928bfa95..6fb7158c 100644
--- a/src/data_imports/DataImportsUI.vala
+++ b/src/data_imports/DataImportsUI.vala
@@ -34,7 +34,7 @@ public class ConcreteDialogPane : Spit.DataImports.DialogPane, GLib.Object {
 public class StaticMessagePane : ConcreteDialogPane {
     public StaticMessagePane(string message_string) {
         Gtk.Label message_label = new Gtk.Label(message_string);
-        (get_widget() as Gtk.Box).pack_start(message_label, true, true, 0);
+        ((Gtk.Box) get_widget()).pack_start(message_label, true, true, 0);
     }
     
     public StaticMessagePane.with_pango(string msg) {
@@ -42,7 +42,7 @@ public class StaticMessagePane : ConcreteDialogPane {
         label.set_markup(msg);
         label.set_line_wrap(true);
         
-        (get_widget() as Gtk.Box).pack_start(label, true, true, 0);
+        ((Gtk.Box) get_widget()).pack_start(label, true, true, 0);
     }
 }
 
@@ -123,7 +123,7 @@ public class LibrarySelectionPane : ConcreteDialogPane {
         button_box.add(import_button);
         content_box.pack_end(button_box, true, false, 6);
         
-        (get_widget() as Gtk.Box).pack_start(content_box, true, true, 0);
+        ((Gtk.Box) get_widget()).pack_start(content_box, true, true, 0);
         
         set_import_button_sensitivity();
     }
@@ -177,7 +177,7 @@ public class ProgressPane : ConcreteDialogPane {
         progress_label = new Gtk.Label("");
         content_box.pack_start(progress_label, false, true, 6);
         
-        (get_widget() as Gtk.Container).add(content_box);
+        ((Gtk.Container) get_widget()).add(content_box);
     }
     
     public void update_progress(double progress, string? progress_message) {
diff --git a/src/dialogs/Preferences.vala b/src/dialogs/Preferences.vala
index 846a9b8e..123a9e0d 100644
--- a/src/dialogs/Preferences.vala
+++ b/src/dialogs/Preferences.vala
@@ -81,7 +81,7 @@ public class PreferencesDialog : Gtk.Dialog {
 
         Gdk.RGBA color = Gdk.RGBA();
         color.parse(Config.Facade.get_instance().get_transparent_background_color());
-        (transparent_solid_color as Gtk.ColorChooser).rgba = color;
+        ((Gtk.ColorChooser) transparent_solid_color).rgba = color;
         transparent_solid_color.color_set.connect(on_color_changed);
 
         switch (Config.Facade.get_instance().get_transparent_background_type()) {
@@ -126,7 +126,7 @@ public class PreferencesDialog : Gtk.Dialog {
 
         lowercase.toggled.connect(on_lowercase_toggled);
 
-        (preferences_notebook.get_nth_page (2) as Gtk.Container).add (plugins_mediator);
+        ((Gtk.Container) preferences_notebook.get_nth_page (2)).add (plugins_mediator);
 
         populate_preference_options();
 
@@ -177,7 +177,7 @@ public class PreferencesDialog : Gtk.Dialog {
     }
 
     private void on_color_changed() {
-        var color = (transparent_solid_color as Gtk.ColorChooser).rgba.to_string();
+        var color = ((Gtk.ColorChooser) transparent_solid_color).rgba.to_string();
         Config.Facade.get_instance().set_transparent_background_color(color);
     }
 
diff --git a/src/direct/DirectPhotoPage.vala b/src/direct/DirectPhotoPage.vala
index 2b7fa258..ca4ea983 100644
--- a/src/direct/DirectPhotoPage.vala
+++ b/src/direct/DirectPhotoPage.vala
@@ -219,8 +219,9 @@ public class DirectPhotoPage : EditingHostPage {
             
             return true;
         } else {
-            if (get_container() is DirectWindow) {
-                (get_container() as DirectWindow).do_fullscreen();
+            var direct_window = get_container() as DirectWindow;
+            if (direct_window != null) {
+                direct_window.do_fullscreen();
 
                 return true;
             }
diff --git a/src/editing_tools/EditingTools.vala b/src/editing_tools/EditingTools.vala
index 07e8e4e5..e2c82565 100644
--- a/src/editing_tools/EditingTools.vala
+++ b/src/editing_tools/EditingTools.vala
@@ -87,7 +87,7 @@ public abstract class EditingToolWindow : Gtk.Window {
     }
 
     public override void realize() {
-        (this as Gtk.Widget).set_opacity(Resources.TRANSIENT_WINDOW_OPACITY);
+        set_opacity(Resources.TRANSIENT_WINDOW_OPACITY);
         
         base.realize();
     }
diff --git a/src/photos/JfifSupport.vala b/src/photos/JfifSupport.vala
index 05b7de9a..0de45f88 100644
--- a/src/photos/JfifSupport.vala
+++ b/src/photos/JfifSupport.vala
@@ -136,6 +136,7 @@ public class JfifSniffer : GdkSniffer {
         var fins = file.read(null);
         var dins = new DataInputStream(fins);
         dins.set_byte_order(DataStreamByteOrder.BIG_ENDIAN);
+        var seekable = (Seekable) dins;
 
         var marker = Jpeg.Marker.INVALID;
         var length = Jpeg.read_marker_2(dins, out marker);
@@ -146,7 +147,7 @@ public class JfifSniffer : GdkSniffer {
 
         length = Jpeg.read_marker_2(dins, out marker);
         while (!marker.is_sof() && length > 0) {
-            (dins as Seekable).seek(length, SeekType.CUR, null);
+            seekable.seek(length, SeekType.CUR, null);
             length = Jpeg.read_marker_2(dins, out marker);
         }
 
@@ -302,9 +303,10 @@ namespace Jpeg {
         }
         
         uint16 length = dins.read_uint16();
-        if (length < 2 && dins is Seekable) {
+        var seekable = dins as Seekable;
+        if (length < 2 && dins != null) {
             debug("Invalid length %Xh at ofs %" + int64.FORMAT + "Xh", length,
-                    (dins as Seekable).tell() - 2);
+                    seekable.tell() - 2);
             
             return -1;
         }
diff --git a/src/searches/SavedSearchDialog.vala b/src/searches/SavedSearchDialog.vala
index 601b5604..012f3370 100644
--- a/src/searches/SavedSearchDialog.vala
+++ b/src/searches/SavedSearchDialog.vala
@@ -708,7 +708,7 @@ public class SavedSearchDialog : Gtk.Dialog {
             var box = search_title.get_parent();
             box.remove(search_title);
             box.get_parent().remove(box);
-            (get_header_bar() as Gtk.HeaderBar).set_custom_title (search_title);
+            ((Gtk.HeaderBar) get_header_bar()).set_custom_title(search_title);
         }
     }
     


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]