freetype-commit
[Top][All Lists]
Advanced

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

[freetype2-demos] ftinspect-grayscale 6da9e90a 1/2: [ftinspect] Fix unin


From: Werner Lemberg
Subject: [freetype2-demos] ftinspect-grayscale 6da9e90a 1/2: [ftinspect] Fix uninitialized memory issue and reference misuse. (#23)
Date: Thu, 2 Mar 2023 12:34:08 -0500 (EST)

branch: ftinspect-grayscale
commit 6da9e90a5779173a611d2bbf66da543415b82a37
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>

    [ftinspect] Fix uninitialized memory issue and reference misuse. (#23)
    
    * src/ftinspect/engine/rendering.cpp:
      Properly initialize `FT_Bitmap` since it's a value type.
      Fix the accident 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 C++ reference.
    
    * src/ftinspect/glyphcomponents/glyphcontinuous.cpp:
      Fix the crash when the `QImage` was failed to produce.
---
 src/ftinspect/engine/rendering.cpp                | 4 ++--
 src/ftinspect/glyphcomponents/glyphcontinuous.cpp | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/ftinspect/engine/rendering.cpp 
b/src/ftinspect/engine/rendering.cpp
index 11ad283b..0b3db536 100644
--- a/src/ftinspect/engine/rendering.cpp
+++ b/src/ftinspect/engine/rendering.cpp
@@ -136,7 +136,7 @@ RenderingEngine::convertGlyphToBitmapGlyph(FT_Glyph src,
 FT_Bitmap
 RenderingEngine::convertBitmapTo8Bpp(FT_Bitmap* bitmap)
 {
-  FT_Bitmap out;
+  FT_Bitmap out = {};
   out.buffer = NULL;
   // This will create a new bitmap object.
   auto error = FT_Bitmap_Convert(engine_->ftLibrary(), bitmap, &out, 1);
@@ -167,7 +167,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]