From bc0b37c56aea73563cf53f84aa75da2a12e4dd71 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 24 Jun 2020 11:45:47 -0700 Subject: [PATCH] Panic when invalid arguments are passed to the C API. Closes #352. --- c/src/lib.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/c/src/lib.rs b/c/src/lib.rs index ba14c346..aa5d4097 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -304,18 +304,20 @@ pub unsafe extern "C" fn PFCanvasSetLineWidth(canvas: PFCanvasRef, new_line_widt #[no_mangle] pub unsafe extern "C" fn PFCanvasSetLineCap(canvas: PFCanvasRef, new_line_cap: PFLineCap) { (*canvas).set_line_cap(match new_line_cap { + PF_LINE_CAP_BUTT => LineCap::Butt, PF_LINE_CAP_SQUARE => LineCap::Square, PF_LINE_CAP_ROUND => LineCap::Round, - _ => LineCap::Butt, + _ => panic!("Invalid Pathfinder line cap style!"), }); } #[no_mangle] pub unsafe extern "C" fn PFCanvasSetLineJoin(canvas: PFCanvasRef, new_line_join: PFLineJoin) { (*canvas).set_line_join(match new_line_join { + PF_LINE_JOIN_MITER => LineJoin::Miter, PF_LINE_JOIN_BEVEL => LineJoin::Bevel, PF_LINE_JOIN_ROUND => LineJoin::Round, - _ => LineJoin::Miter, + _ => panic!("Invalid Pathfinder line join style!"), }); } @@ -453,7 +455,11 @@ pub unsafe extern "C" fn PFPathArc(path: PFPathRef, start_angle: f32, end_angle: f32, direction: PFArcDirection) { - let direction = if direction == 0 { ArcDirection::CW } else { ArcDirection::CCW }; + let direction = match direction { + PF_ARC_DIRECTION_CW => ArcDirection::CW, + PF_ARC_DIRECTION_CCW => ArcDirection::CCW, + _ => panic!("Invalid Pathfinder arc direction!"), + }; (*path).arc((*center).to_rust(), radius, start_angle, end_angle, direction) } @@ -858,7 +864,8 @@ impl PFRendererOptions { fn to_rust_renderer_level(level: PFRendererLevel) -> RendererLevel { match level { - PF_RENDERER_LEVEL_D3D9 => RendererLevel::D3D9, - _ => RendererLevel::D3D11, + PF_RENDERER_LEVEL_D3D9 => RendererLevel::D3D9, + PF_RENDERER_LEVEL_D3D11 => RendererLevel::D3D11, + _ => panic!("Invalid Pathfinder renderer level!"), } }