freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master b33c0ecf: [ftinspect] Fix uninitialized memory


From: Werner Lemberg
Subject: [freetype2-demos] master b33c0ecf: [ftinspect] Fix uninitialized memory issue and reference misuse.
Date: Fri, 3 Mar 2023 03:53:27 -0500 (EST)

branch: master
commit b33c0ecfae2e2426bd32a3e916100f5624610632
Author: Charlie Jiang <w@chariri.moe>
Commit: Werner Lemberg <wl@gnu.org>

    [ftinspect] Fix uninitialized memory issue and reference misuse.
    
    Fixes issue #23.
    
    * src/ftinspect/engine/rendering.cpp (RenderingEngine::convertBitmapTo8Bpp):
    Properly initialize `FT_Bitmap` since it is a value type.
    (RenderingEngine::convertBitmapToQImage): Fix the accidental overwriting of
    the source bitmap when converting the bitmap format (only happens for
    `FT_PIXEL_MODE_GRAY2` and `FT_PIXEL_MODE_GRAY4`) due to a misuse of a C++
    reference.
    
    * src/ftinspect/glyphcomponents/glyphcontinuous.cpp
    (GlyphContinuous::drawCacheGlyph): Fix a crash when the `QImage` was failed
    to produce.
---
 src/ftinspect/engine/rendering.cpp                | 5 ++---
 src/ftinspect/glyphcomponents/glyphcontinuous.cpp | 2 ++
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/ftinspect/engine/rendering.cpp 
b/src/ftinspect/engine/rendering.cpp
index 11ad283b..524f0a56 100644
--- a/src/ftinspect/engine/rendering.cpp
+++ b/src/ftinspect/engine/rendering.cpp
@@ -136,8 +136,7 @@ RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src,
 FT_Bitmap
 RenderingEngine::convertBitmapTo8Bpp(FT_Bitmap* bitmap)
 {
-  FT_Bitmap out;
-  out.buffer = NULL;
+  FT_Bitmap out = {};
   // This will create a new bitmap object.
   auto error = FT_Bitmap_Convert(engine_->ftLibrary(), bitmap, &out, 1);
   if (error)
@@ -167,7 +166,7 @@ RenderingEngine::convertBitmapToQImage(FT_Bitmap* src)
 {
   QImage* result = NULL;
 
-  auto& bmap = *src;
+  auto bmap = *src;
   bool ownBitmap = false; // If true, we need to clean up `bmap`.
 
   int width = INT_MAX;
diff --git a/src/ftinspect/glyphcomponents/glyphcontinuous.cpp 
b/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
index c8fdb526..13e7e96f 100644
--- a/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
+++ b/src/ftinspect/glyphcomponents/glyphcontinuous.cpp
@@ -552,6 +552,8 @@ GlyphContinuous::drawCacheGlyph(QPainter* painter,
                                 const GlyphCacheEntry& entry,
                                 bool colorInverted)
 {
+  if (!entry.image)
+    return;
   // From `ftview.c:557`.
   // Well, metrics are also part of the cache...
   int width = entry.advance.x ? entry.advance.x >> 16



reply via email to

[Prev in Thread] Current Thread [Next in Thread]