diff --git a/src/actions/splash.rs b/src/actions/splash.rs index b37eed8..4fbd8c7 100644 --- a/src/actions/splash.rs +++ b/src/actions/splash.rs @@ -1,7 +1,7 @@ use crate::context::SproutContext; use crate::utils::framebuffer::Framebuffer; use crate::utils::read_file_contents; -use anyhow::{Context, Result}; +use anyhow::{Context, Result, bail}; use image::imageops::{FilterType, resize}; use image::math::Rect; use image::{DynamicImage, ImageBuffer, ImageFormat, ImageReader, Rgba}; @@ -118,6 +118,11 @@ fn draw(image: DynamicImage) -> Result<()> { // Fit the image to the display frame. let fit = fit_to_frame(&image, display_frame); + // If the image is zero-sized, then we should bail with an error. + if fit.width == 0 || fit.height == 0 { + bail!("calculated frame size is zero"); + } + // Resize the image to fit the display frame. let image = resize_to_fit(&image, fit); diff --git a/src/platform/timer.rs b/src/platform/timer.rs index 303ee5c..f004dc6 100644 --- a/src/platform/timer.rs +++ b/src/platform/timer.rs @@ -53,9 +53,14 @@ fn arch_ticks() -> u64 { /// Acquire the tick frequency reported by the platform. fn arch_frequency() -> TickFrequency { #[cfg(target_arch = "aarch64")] - return aarch64::frequency(); + let frequency = aarch64::frequency(); #[cfg(target_arch = "x86_64")] - return x86_64::frequency(); + let frequency = x86_64::frequency(); + // If the frequency is 0, then something went very wrong and we should panic. + if frequency.ticks() == 0 { + panic!("timer frequency is zero"); + } + frequency } /// Platform timer that allows measurement of the elapsed time. diff --git a/src/platform/timer/x86_64.rs b/src/platform/timer/x86_64.rs index 51d70f1..7736dab 100644 --- a/src/platform/timer/x86_64.rs +++ b/src/platform/timer/x86_64.rs @@ -62,9 +62,5 @@ fn measure_frequency() -> u64 { /// On x86_64, this is slightly expensive, so it should be done once. pub fn frequency() -> TickFrequency { let frequency = measure_frequency(); - // If the frequency is 0, then something went very wrong and we should panic. - if frequency == 0 { - panic!("unable to measure frequency"); - } TickFrequency::Measured(frequency, MEASURE_FREQUENCY_DURATION) }