diff --git a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp index bd1377ef0..c86fa2ec5 100644 --- a/src/Magnum/Text/Test/AbstractFontConverterTest.cpp +++ b/src/Magnum/Text/Test/AbstractFontConverterTest.cpp @@ -64,6 +64,13 @@ AbstractFontConverterTest::AbstractFontConverterTest() { &AbstractFontConverterTest::importGlyphCacheFromFile}); } +namespace { + /* *static_cast(nullptr) makes Clang Analyzer grumpy */ + unsigned char nullData; + AbstractFont& nullFont = *reinterpret_cast(nullData); + GlyphCache& nullGlyphCache = *reinterpret_cast(nullData); +} + void AbstractFontConverterTest::convertGlyphs() { class GlyphExporter: public AbstractFontConverter { public: @@ -99,7 +106,7 @@ void AbstractFontConverterTest::convertGlyphs() { std::vector characters; #endif GlyphExporter exporter(characters); - exporter.exportFontToSingleData(*static_cast(nullptr), *static_cast(nullptr), "abC01a0 "); + exporter.exportFontToSingleData(nullFont, nullGlyphCache, "abC01a0 "); #ifndef __MINGW32__ CORRADE_COMPARE(characters, U" 01Cab"); #else @@ -127,7 +134,7 @@ void AbstractFontConverterTest::exportFontToSingleData() { /* doExportFontToData() should call doExportFontToSingleData() */ SingleDataExporter exporter; - auto ret = exporter.exportFontToData(*static_cast(nullptr), *static_cast(nullptr), "font.out", {}); + auto ret = exporter.exportFontToData(nullFont, nullGlyphCache, "font.out", {}); CORRADE_COMPARE(ret.size(), 1); CORRADE_COMPARE(ret[0].first, "font.out"); CORRADE_COMPARE(ret[0].second.size(), 1); @@ -165,7 +172,7 @@ void AbstractFontConverterTest::exportFontToFile() { /* doExportToFile() should call doExportToData() */ DataExporter exporter; - bool exported = exporter.exportFontToFile(*static_cast(nullptr), *static_cast(nullptr), Utility::Directory::join(TEXT_TEST_OUTPUT_DIR, "font.out"), {}); + bool exported = exporter.exportFontToFile(nullFont, nullGlyphCache, Utility::Directory::join(TEXT_TEST_OUTPUT_DIR, "font.out"), {}); CORRADE_VERIFY(exported); CORRADE_COMPARE_AS(Utility::Directory::join(TEXT_TEST_OUTPUT_DIR, "font.out"), "\xf0", TestSuite::Compare::FileToString); @@ -187,7 +194,7 @@ void AbstractFontConverterTest::exportGlyphCacheToSingleData() { /* doExportGlyphCacheToData() should call doExportGlyphCacheToSingleData() */ SingleDataExporter exporter; - auto ret = exporter.exportGlyphCacheToData(*static_cast(nullptr), "font.out"); + auto ret = exporter.exportGlyphCacheToData(nullGlyphCache, "font.out"); CORRADE_COMPARE(ret.size(), 1); CORRADE_COMPARE(ret[0].first, "font.out"); CORRADE_COMPARE(ret[0].second.size(), 1); @@ -220,7 +227,7 @@ void AbstractFontConverterTest::exportGlyphCacheToFile() { /* doExportGlyphCacheToFile() should call doExportGlyphCacheToData() */ DataExporter exporter; - bool exported = exporter.exportGlyphCacheToFile(*static_cast(nullptr), Utility::Directory::join(TEXT_TEST_OUTPUT_DIR, "glyphcache.out")); + bool exported = exporter.exportGlyphCacheToFile(nullGlyphCache, Utility::Directory::join(TEXT_TEST_OUTPUT_DIR, "glyphcache.out")); CORRADE_VERIFY(exported); CORRADE_COMPARE_AS(Utility::Directory::join(TEXT_TEST_OUTPUT_DIR, "glyphcache.out"), "\xf0", TestSuite::Compare::FileToString); diff --git a/src/Magnum/Text/Test/RendererGLTest.cpp b/src/Magnum/Text/Test/RendererGLTest.cpp index 561ca0d50..0d5ff4b30 100644 --- a/src/Magnum/Text/Test/RendererGLTest.cpp +++ b/src/Magnum/Text/Test/RendererGLTest.cpp @@ -82,6 +82,10 @@ class TestFont: public Text::AbstractFont { } }; +/* *static_cast(nullptr) makes Clang Analyzer grumpy */ +unsigned char glyphCacheData; +GlyphCache& nullGlyphCache = *reinterpret_cast(&glyphCacheData); + } void RendererGLTest::renderData() { @@ -90,7 +94,7 @@ void RendererGLTest::renderData() { std::vector textureCoordinates; std::vector indices; Range2D bounds; - std::tie(positions, textureCoordinates, indices, bounds) = Text::AbstractRenderer::render(font, *static_cast(nullptr), 0.25f, "abc", Alignment::MiddleRightIntegral); + std::tie(positions, textureCoordinates, indices, bounds) = Text::AbstractRenderer::render(font, nullGlyphCache, 0.25f, "abc", Alignment::MiddleRightIntegral); /* Three glyphs, three quads -> 12 vertices, 18 indices */ CORRADE_COMPARE(positions.size(), 12); @@ -172,7 +176,7 @@ void RendererGLTest::renderMesh() { Mesh mesh; Buffer vertexBuffer, indexBuffer; Range2D bounds; - std::tie(mesh, bounds) = Text::Renderer3D::render(font, *static_cast(nullptr), + std::tie(mesh, bounds) = Text::Renderer3D::render(font, nullGlyphCache, 0.25f, "abc", vertexBuffer, indexBuffer, BufferUsage::StaticDraw, Alignment::TopCenter); MAGNUM_VERIFY_NO_ERROR(); @@ -224,7 +228,7 @@ void RendererGLTest::renderMeshIndexType() { texture coordinates, each float is four bytes; six indices per glyph. */ /* 8-bit indices (exactly 256 vertices) */ - std::tie(mesh, std::ignore) = Text::Renderer3D::render(font, *static_cast(nullptr), + std::tie(mesh, std::ignore) = Text::Renderer3D::render(font, nullGlyphCache, 1.0f, std::string(64, 'a'), vertexBuffer, indexBuffer, BufferUsage::StaticDraw); MAGNUM_VERIFY_NO_ERROR(); Containers::Array indicesByte = indexBuffer.data(); @@ -237,7 +241,7 @@ void RendererGLTest::renderMeshIndexType() { })); /* 16-bit indices (260 vertices) */ - std::tie(mesh, std::ignore) = Text::Renderer3D::render(font, *static_cast(nullptr), + std::tie(mesh, std::ignore) = Text::Renderer3D::render(font, nullGlyphCache, 1.0f, std::string(65, 'a'), vertexBuffer, indexBuffer, BufferUsage::StaticDraw); MAGNUM_VERIFY_NO_ERROR(); Containers::Array indicesShort = indexBuffer.data(); @@ -266,7 +270,7 @@ void RendererGLTest::mutableText() { #endif TestFont font; - Text::Renderer2D renderer(font, *static_cast(nullptr), 0.25f); + Text::Renderer2D renderer(font, nullGlyphCache, 0.25f); MAGNUM_VERIFY_NO_ERROR(); CORRADE_COMPARE(renderer.capacity(), 0); CORRADE_COMPARE(renderer.rectangle(), Range2D()); @@ -359,7 +363,7 @@ void RendererGLTest::multiline() { std::vector indices; std::vector positions, textureCoordinates; std::tie(positions, textureCoordinates, indices, rectangle) = Text::Renderer2D::render(font, - *static_cast(nullptr), 2.0f, "abcd\nef\n\nghi", Alignment::MiddleCenter); + nullGlyphCache, 2.0f, "abcd\nef\n\nghi", Alignment::MiddleCenter); /* We're rendering text at 2.0f size and the font is scaled to 0.3f, so the line advance should be 0.75f*2.0f/0.5f = 3.0f */