From f6d5f9728c22529da8e93ec28b2c4de5109298d7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 May 2015 18:14:17 +0200 Subject: [PATCH] Don't use arrays indexed by font weight/styles in wxSVGFileDC. This is not natural for the non-consecutive values of the font styles and doesn't properly check for the array indices being valid, resulting in static analysis tools warnings about a possibly out of bound array access. --- src/common/dcsvg.cpp | 50 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index 64025aa884..5f09c623c0 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -385,11 +385,53 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor if (sTmp.Len() > 0) s += wxT("style=\"font-family:") + sTmp + wxT("; "); else s += wxT("style=\" "); - wxString fontweights [3] = { wxT("normal"), wxT("lighter"), wxT("bold") }; - s += wxT("font-weight:") + fontweights[m_font.GetWeight() - wxNORMAL] + wxT("; "); + wxString fontweight; + switch ( m_font.GetWeight() ) + { + case wxFONTWEIGHT_MAX: + wxFAIL_MSG( wxS("invalid font weight value") ); + wxFALLTHROUGH; - wxString fontstyles [5] = { wxT("normal"), wxT("style error"), wxT("style error"), wxT("italic"), wxT("oblique") }; - s += wxT("font-style:") + fontstyles[m_font.GetStyle() - wxNORMAL] + wxT("; "); + case wxFONTWEIGHT_NORMAL: + fontweight = wxS("normal"); + break; + + case wxFONTWEIGHT_LIGHT: + fontweight = wxS("lighter"); + break; + + case wxFONTWEIGHT_BOLD: + fontweight = wxS("bold"); + break; + } + + wxASSERT_MSG( !fontweight.empty(), wxS("unknown font weight value") ); + + s += wxT("font-weight:") + fontweight + wxT("; "); + + wxString fontstyle; + switch ( m_font.GetStyle() ) + { + case wxFONTSTYLE_MAX: + wxFAIL_MSG( wxS("invalid font style value") ); + wxFALLTHROUGH; + + case wxFONTSTYLE_NORMAL: + fontstyle = wxS("normal"); + break; + + case wxFONTSTYLE_ITALIC: + fontstyle = wxS("italic"); + break; + + case wxFONTSTYLE_SLANT: + fontstyle = wxS("oblique"); + break; + } + + wxASSERT_MSG( !fontstyle.empty(), wxS("unknown font style value") ); + + s += wxT("font-style:") + fontstyle + wxT("; "); sTmp.Printf (wxT("font-size:%dpt; "), m_font.GetPointSize() ); s += sTmp;