Re: [PATCH] Fix undefined behaviour

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

 



On 06.12.22 12:24, Marko Mäkelä wrote:
...
diff --git a/dvbsubtitle.c b/dvbsubtitle.c
index c1dfef4d..2d22d963 100644
--- a/dvbsubtitle.c
+++ b/dvbsubtitle.c
@@ -1770,6 +1770,8 @@ void cDvbSubtitleConverter::FinishPage(cDvbSubtitlePage *Page)
       return;
    int NumAreas;
    tArea *Areas = Page->GetAreas(NumAreas);
+  if (!Areas)
+     return;
    tArea AreaCombined = Page->CombineAreas(NumAreas, Areas);
    tArea AreaOsd = Page->ScaleArea(AreaCombined, osdFactorX, osdFactorY);
    int Bpp = 8;

OK, let's settle for this (if there are no areas, the check for 'NumAreas > 0' is obsolete):

--- dvbsubtitle.c       2021/03/17 15:24:34     5.1
+++ dvbsubtitle.c       2022/12/06 16:44:02
@@ -1770,11 +1770,13 @@
      return;
   int NumAreas;
   tArea *Areas = Page->GetAreas(NumAreas);
+  if (!Areas)
+     return;
   tArea AreaCombined = Page->CombineAreas(NumAreas, Areas);
   tArea AreaOsd = Page->ScaleArea(AreaCombined, osdFactorX, osdFactorY);
   int Bpp = 8;
   bool Reduced = false;
-  if (osd && NumAreas > 0) {
+  if (osd) {
      while (osd->CanHandleAreas(&AreaOsd, 1) != oeOk) {
            dbgoutput("CanHandleAreas: %d<br>\n", osd->CanHandleAreas(&AreaOsd, 1));
            int HalfBpp = Bpp / 2;

... > @@ -74,7 +74,8 @@ cGlyph::cGlyph(uint CharCode, FT_GlyphSlotRec_ *GlyphData)
    rows = GlyphData->bitmap.rows;
    pitch = GlyphData->bitmap.pitch;
    bitmap = MALLOC(uchar, rows * pitch);
-  memcpy(bitmap, GlyphData->bitmap.buffer, rows * pitch);
+  if (int bytes = rows * pitch)
+     memcpy(bitmap, GlyphData->bitmap.buffer, bytes);
  }
cGlyph::~cGlyph()

OK, 'man malloc' says "If size is 0, then malloc() returns either NULL, or a unique pointer value that can later
be successfully passed to free()". Since memcpy() must not be called with a NULL pointer, you win.

Klaus


_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
https://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr




[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux