changeset 921:2454ddb7363f

Add constant for max number of enc/dec ops in C64 image format struct and check the specified amount against that.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Feb 2015 14:19:46 +0200
parents 9be156fa4b9d
children 658bf4c452d0
files tools/lib64gfx.c tools/lib64gfx.h
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Wed Feb 25 14:09:18 2015 +0200
+++ b/tools/lib64gfx.c	Wed Feb 25 14:19:46 2015 +0200
@@ -610,6 +610,12 @@
     if (buf == NULL || img == NULL || fmt == NULL)
         return DMERR_NULLPTR;
 
+    if (fmt->nencdecOps < 0 || fmt->nencdecOps >= D64_MAX_ENCDEC_OPS)
+    {
+        dmError("Invalid number of enc/dec ops in format. Internal error.\n");
+        return DMERR_INTERNAL;
+    }
+
     // Clear the image structure
     memset(img, 0, sizeof(*img));
     img->type = fmt->type;
@@ -738,6 +744,12 @@
     if (pbuf == NULL || plen == NULL || img == NULL || fmt == NULL)
         return DMERR_NULLPTR;
 
+    if (fmt->nencdecOps < 0 || fmt->nencdecOps >= D64_MAX_ENCDEC_OPS)
+    {
+        dmError("Invalid number of enc/dec ops in format. Internal error.\n");
+        return DMERR_INTERNAL;
+    }
+
     // Allocate the output buffer
     *plen = 0;
     if (fmt->size > 0)
--- a/tools/lib64gfx.h	Wed Feb 25 14:09:18 2015 +0200
+++ b/tools/lib64gfx.h	Wed Feb 25 14:19:46 2015 +0200
@@ -174,6 +174,9 @@
 } DMC64EncDecOp;
 
 
+#define D64_MAX_ENCDEC_OPS 16
+
+
 typedef struct _DMC64ImageFormat
 {
     int  type;
@@ -188,7 +191,7 @@
     int  (*convertTo)(DMImage *, DMC64Image *);
 
     int nencdecOps;
-    DMC64EncDecOp encdecOps[16];
+    DMC64EncDecOp encdecOps[D64_MAX_ENCDEC_OPS];
 } DMC64ImageFormat;