From 3598fc24625f233cc0078f62da630d335604ef5b Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Fri, 18 Nov 2022 15:57:18 +1300 Subject: [PATCH] Add more unboxing & null-checks to FcValue decoding. --- Graphics/Text/Font/Choose/Value.hs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Graphics/Text/Font/Choose/Value.hs b/Graphics/Text/Font/Choose/Value.hs index 9e03e81..ce20729 100644 --- a/Graphics/Text/Font/Choose/Value.hs +++ b/Graphics/Text/Font/Choose/Value.hs @@ -102,16 +102,24 @@ thawValue ptr = do 0 -> return $ Just ValueVoid 1 -> Just <$> ValueInt <$> peek val' 2 -> Just <$> ValueDouble <$> peek val' - 3 -> Just <$> ValueString <$> peekCString val' + 3 -> do + val <- throwNull <$> peek val' + Just <$> ValueString <$> peekCString val 4 -> do - mat' <- peek val' + mat' <- throwNull <$> peek val' xx <- peekElemOff mat' 0 xy <- peekElemOff mat' 1 yx <- peekElemOff mat' 2 yy <- peekElemOff mat' 3 return $ Just $ ValueMatrix $ V2 (V2 xx yx) (V2 xy yy) - 5 -> Just <$> ValueCharSet <$> thawCharSet val' - 6 -> return $ Just $ ValueFTFace $ val' - 7 -> Just <$> ValueLangSet <$> thawLangSet val' - 8 -> Just <$> ValueRange <$> thawRange val' + 5 -> do + val <- throwNull <$> peek val' + Just <$> ValueCharSet <$> thawCharSet val + 6 -> Just <$> ValueFTFace <$> throwNull <$> peek val' + 7 -> do + val <- throwNull <$> peek val' + Just <$> ValueLangSet <$> thawLangSet val + 8 -> do + val <- throwNull <$> peek val' + Just <$> ValueRange <$> thawRange val _ -> return Nothing -- 2.30.2