Skip to content

Commit 757d10e

Browse files
committed
fix(timer): add check for zero frequency
1 parent 3b32f6c commit 757d10e

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/actions/splash.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::context::SproutContext;
22
use crate::utils::framebuffer::Framebuffer;
33
use crate::utils::read_file_contents;
4-
use anyhow::{Context, Result};
4+
use anyhow::{Context, Result, bail};
55
use image::imageops::{FilterType, resize};
66
use image::math::Rect;
77
use image::{DynamicImage, ImageBuffer, ImageFormat, ImageReader, Rgba};
@@ -118,6 +118,11 @@ fn draw(image: DynamicImage) -> Result<()> {
118118
// Fit the image to the display frame.
119119
let fit = fit_to_frame(&image, display_frame);
120120

121+
// If the image is zero-sized, then we should bail with an error.
122+
if fit.width == 0 || fit.height == 0 {
123+
bail!("calculated frame size is zero");
124+
}
125+
121126
// Resize the image to fit the display frame.
122127
let image = resize_to_fit(&image, fit);
123128

src/platform/timer.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ fn arch_ticks() -> u64 {
5353
/// Acquire the tick frequency reported by the platform.
5454
fn arch_frequency() -> TickFrequency {
5555
#[cfg(target_arch = "aarch64")]
56-
return aarch64::frequency();
56+
let frequency = aarch64::frequency();
5757
#[cfg(target_arch = "x86_64")]
58-
return x86_64::frequency();
58+
let frequency = x86_64::frequency();
59+
// If the frequency is 0, then something went very wrong and we should panic.
60+
if frequency.ticks() == 0 {
61+
panic!("timer frequency is zero");
62+
}
63+
frequency
5964
}
6065

6166
/// Platform timer that allows measurement of the elapsed time.

src/platform/timer/x86_64.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,5 @@ fn measure_frequency() -> u64 {
6262
/// On x86_64, this is slightly expensive, so it should be done once.
6363
pub fn frequency() -> TickFrequency {
6464
let frequency = measure_frequency();
65-
// If the frequency is 0, then something went very wrong and we should panic.
66-
if frequency == 0 {
67-
panic!("unable to measure frequency");
68-
}
6965
TickFrequency::Measured(frequency, MEASURE_FREQUENCY_DURATION)
7066
}

0 commit comments

Comments
 (0)