From ea80e2c8d5f5e2c94448aaf76ff686287c6ee5fe Mon Sep 17 00:00:00 2001 From: Michael Catanzaro Date: Tue, 14 Apr 2020 14:51:34 -0500 Subject: [PATCH] Fix crashes when sunrise/sunset calculation goes badly --- gnome-clocks.spec | 8 +- null-datetime-crash.patch | 210 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 null-datetime-crash.patch diff --git a/gnome-clocks.spec b/gnome-clocks.spec index afd3eb9..f74a75a 100644 --- a/gnome-clocks.spec +++ b/gnome-clocks.spec @@ -2,13 +2,16 @@ Name: gnome-clocks Version: 3.36.0 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Clock application designed for GNOME 3 License: GPLv2+ URL: https://wiki.gnome.org/Apps/Clocks Source0: https://download.gnome.org/sources/gnome-clocks/3.36/%{name}-%{version}.tar.xz +# https://gitlab.gnome.org/GNOME/gnome-clocks/-/issues/91 +Patch0: null-datetime-crash.patch + BuildRequires: meson BuildRequires: desktop-file-utils BuildRequires: gettext @@ -60,6 +63,9 @@ desktop-file-validate $RPM_BUILD_ROOT%{_datadir}/applications/org.gnome.clocks.d %{_datadir}/metainfo/org.gnome.clocks.metainfo.xml %changelog +* Tue Apr 14 2020 Michael Catanzaro - 3.36.0-2 +- Fix crashes when sunrise/sunset calculation goes badly + * Thu Mar 05 2020 Kalev Lember - 3.36.0-1 - Update to 3.36.0 diff --git a/null-datetime-crash.patch b/null-datetime-crash.patch new file mode 100644 index 0000000..c0a4f69 --- /dev/null +++ b/null-datetime-crash.patch @@ -0,0 +1,210 @@ +From db85dd563e1adbbb697acffc25e2c22eac1bbb32 Mon Sep 17 00:00:00 2001 +From: Zander Brown +Date: Fri, 10 Apr 2020 15:16:03 +0100 +Subject: [PATCH] world: handle null datetime + +Of course we need to figure out how we got garbage that generated a null +datetime but at least this way we don't crash (and get logs) + +(Kinda) Fix https://gitlab.gnome.org/GNOME/gnome-clocks/-/issues/91 +--- + src/world.vala | 169 +++++++++++++++++++++++++++++-------------------- + 1 file changed, 99 insertions(+), 70 deletions(-) + +diff --git a/src/world.vala b/src/world.vala +index 0da51bf..c212b02 100644 +--- a/src/world.vala ++++ b/src/world.vala +@@ -251,90 +251,119 @@ public class Item : Object, ContentItem { + tick (); + } + +- private void calculate_riseset () { +- double lat, lon; +- int y, m, d; ++ private void calculate_riseset_at_correction (double latitude, ++ double longitude, ++ int year, ++ int month, ++ int day, ++ double correction, ++ out DateTime sunrise, ++ out DateTime sunset) { + int rise_hour, rise_min; + int set_hour, set_min; + ++ calculate_sunrise_sunset (latitude, ++ longitude, ++ year, ++ month, ++ day, ++ correction, ++ out rise_hour, ++ out rise_min, ++ out set_hour, ++ out set_min); ++ ++ var utc_sunrise = new DateTime.utc (year, month, day, rise_hour, rise_min, 0); ++ if (utc_sunrise != null) { ++ sunrise = utc_sunrise.to_timezone (time_zone); ++ } else { ++ sunrise = null; ++ warning ("Sunrise for (%f,%f) resulted in %04i-%02i-%02i %02i:%02i", ++ latitude, ++ longitude, ++ year, ++ month, ++ day, ++ rise_hour, ++ rise_min); ++ } ++ ++ var utc_sunset = new DateTime.utc (year, month, day, set_hour, set_min, 0); ++ if (utc_sunset != null) { ++ var local_sunset = utc_sunset.to_timezone (time_zone); ++ if (local_sunset.compare (sun_rise) < 0) { ++ sunset = local_sunset.add_days (1); ++ } else { ++ sunset = local_sunset; ++ } ++ } else { ++ sunset = null; ++ warning ("Sunset for (%f,%f) resulted in %04i-%02i-%02i %02i:%02i", ++ latitude, ++ longitude, ++ year, ++ month, ++ day, ++ rise_hour, ++ rise_min); ++ } ++ } ++ ++ private void calculate_riseset () { ++ // Where we are calculating for ++ double latitude, longitude; ++ // The current UTC day ++ int year, month, day; ++ + if (date_time.get_day_of_year () == last_calc_day) { + return; + } + +- location.get_coords (out lat, out lon); ++ location.get_coords (out latitude, out longitude); + + // Some locations, such as UTC, aren't actual locations and don't have + // proper coords +- if (!lat.is_finite () || !lon.is_finite ()) { ++ if (!latitude.is_finite () || !longitude.is_finite ()) { + return; + } + + var utc = date_time.to_utc (); +- utc.get_ymd (out y, out m, out d); +- +- calculate_sunrise_sunset (lat, +- lon, +- y, +- m, +- d, +- RISESET_CORRECTION_NONE, +- out rise_hour, +- out rise_min, +- out set_hour, +- out set_min); +- +- sun_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone); +- sun_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone); +- if (sun_set.compare (sun_rise) < 0) +- sun_set = sun_set.add_days (1); +- +- calculate_sunrise_sunset (lat, +- lon, +- y, +- m, +- d, +- RISESET_CORRECTION_CIVIL, +- out rise_hour, +- out rise_min, +- out set_hour, +- out set_min); +- +- civil_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone); +- civil_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone); +- if (civil_set.compare (civil_rise) < 0) +- civil_set = civil_set.add_days (1); +- +- calculate_sunrise_sunset (lat, +- lon, +- y, +- m, +- d, +- RISESET_CORRECTION_NAUTICAL, +- out rise_hour, +- out rise_min, +- out set_hour, +- out set_min); +- +- naut_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone); +- naut_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone); +- if (naut_set.compare (naut_rise) < 0) +- naut_set = naut_set.add_days (1); +- +- calculate_sunrise_sunset (lat, +- lon, +- y, +- m, +- d, +- RISESET_CORRECTION_ASTRONOMICAL, +- out rise_hour, +- out rise_min, +- out set_hour, +- out set_min); +- +- astro_rise = new DateTime.utc (y, m, d, rise_hour, rise_min, 0).to_timezone (time_zone); +- astro_set = new DateTime.utc (y, m, d, set_hour, set_min, 0).to_timezone (time_zone); +- if (astro_set.compare (astro_rise) < 0) +- astro_set = astro_set.add_days (1); ++ utc.get_ymd (out year, out month, out day); ++ ++ calculate_riseset_at_correction (latitude, ++ longitude, ++ year, ++ month, ++ day, ++ RISESET_CORRECTION_NONE, ++ out sun_rise, ++ out sun_set); ++ calculate_riseset_at_correction (latitude, ++ longitude, ++ year, ++ month, ++ day, ++ RISESET_CORRECTION_CIVIL, ++ out civil_rise, ++ out civil_set); ++ calculate_riseset_at_correction (latitude, ++ longitude, ++ year, ++ month, ++ day, ++ RISESET_CORRECTION_NAUTICAL, ++ out naut_rise, ++ out naut_set); ++ calculate_riseset_at_correction (latitude, ++ longitude, ++ year, ++ month, ++ day, ++ RISESET_CORRECTION_ASTRONOMICAL, ++ out astro_rise, ++ out astro_set); ++ ++ last_calc_day = date_time.get_day_of_year (); + } + + [Signal (run = "first")] +-- +2.24.1 +