changeset 2080:7e4087e2740d

Define macros DM_MEMCMP_SIZE() and DM_MEMCMP_LEN() as helpers.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Dec 2018 19:36:48 +0200
parents 9b6027d51f76
children a14286e2710e
files tools/lib64fmts.c
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64fmts.c	Mon Dec 10 19:24:45 2018 +0200
+++ b/tools/lib64fmts.c	Mon Dec 10 19:36:48 2018 +0200
@@ -8,6 +8,8 @@
  */
 #include "lib64gfx.h"
 
+#define DM_MEMCMP_SIZE(mptr, mcmp) memcmp((mptr), (mcmp), sizeof(mcmp))
+#define DM_MEMCMP_LEN(mptr, mcmp) memcmp((mptr), (mcmp), strlen(mcmp))
 
 static int fmtProbeGigapaintHires(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
 {
@@ -35,9 +37,9 @@
 static int fmtProbeMicroIllustrator(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
 {
     if (buf->len == fmt->size &&
-        memcmp(buf->data + 2, fmtMicroIllustratorMagicID_1, sizeof(fmtMicroIllustratorMagicID_1)) == 0
+        DM_MEMCMP_SIZE(buf->data + 2, fmtMicroIllustratorMagicID_1) == 0
         &&
-        memcmp(buf->data + 9, fmtMicroIllustratorMagicID_2, sizeof(fmtMicroIllustratorMagicID_2)) == 0
+        DM_MEMCMP_SIZE(buf->data + 9, fmtMicroIllustratorMagicID_2) == 0
         )
         return DM_PROBE_SCORE_MAX;
 
@@ -158,7 +160,7 @@
     const Uint8 *ident = buf->data + 2;
     if (buf->len > 22 &&
         dmCompareAddr16(buf, 0, fmt->addr) &&
-        memcmp(ident, "DRAZPAINT ", 10) == 0 &&
+        DM_MEMCMP_LEN(ident, "DRAZPAINT ") == 0 &&
         ident[11] == '.' && (
         (ident[10] == '1' && ident[12] == '4') ||
         (ident[10] == '2' && ident[12] == '0')
@@ -233,7 +235,7 @@
 {
     if (buf->len > 22 &&
         dmCompareAddr16(buf, 0, fmt->addr) &&
-        memcmp(buf->data + 2, "DRAZLACE! 1.0", 13) == 0)
+        DM_MEMCMP_LEN(buf->data + 2, "DRAZLACE! 1.0") == 0)
         return DM_PROBE_SCORE_MAX;
 
     return DM_PROBE_SCORE_FALSE;
@@ -269,7 +271,7 @@
 {
     if (buf->len > 20 &&
         dmCompareAddr16(buf, 0, fmt->addr) &&
-        memcmp(buf->data + 2, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) == 0)
+        DM_MEMCMP_LEN(buf->data + 2, fmtBDP5MagicID) == 0)
         return DM_PROBE_SCORE_MAX;
 
     return DM_PROBE_SCORE_FALSE;
@@ -610,7 +612,7 @@
 
     if (buf->len >= 320 &&
         dmCompareAddr16(buf, 0, fmt->addr) &&
-        memcmp(buf->data + 2, magicID, sizeof(magicID)) == 0)
+        DM_MEMCMP_SIZE(buf->data + 2, magicID) == 0)
         return DM_PROBE_SCORE_MAX;
 
     return DM_PROBE_SCORE_FALSE;
@@ -788,8 +790,7 @@
 static int fmtProbeFunPaint2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt)
 {
     if (buf->len > 30 &&
-        dmCompareAddr16(buf, 0, fmt->addr) &&
-        memcmp(buf->data + 2, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0)
+        DM_MEMCMP_LEN(buf->data + 2, fmtFunPaint2MagicID) == 0)
     {
         // Unpacked variant
         if (fmt->size != 0 && buf->data[14 + 2] == 0)