Revision: 76921
          http://sourceforge.net/p/brlcad/code/76921
Author:   starseeker
Date:     2020-08-24 15:30:50 +0000 (Mon, 24 Aug 2020)
Log Message:
-----------
Add a BU_CKMAG check to ensure vls returning function calls can never return 
NULL.

Modified Paths:
--------------
    brlcad/trunk/include/bu/magic.h
    brlcad/trunk/include/dm/defines.h
    brlcad/trunk/src/libdm/X/dm-X.c
    brlcad/trunk/src/libdm/dm-generic.c
    brlcad/trunk/src/libdm/glx/dm-ogl.c
    brlcad/trunk/src/libdm/null/dm-Null.c
    brlcad/trunk/src/libdm/osgl/dm-osgl.cpp
    brlcad/trunk/src/libdm/plot/dm-plot.c
    brlcad/trunk/src/libdm/postscript/dm-ps.c
    brlcad/trunk/src/libdm/qt/dm-qt.cpp
    brlcad/trunk/src/libdm/tk/dm-tk.c
    brlcad/trunk/src/libdm/txt/dm-txt.c
    brlcad/trunk/src/libdm/wgl/dm-wgl.c

Modified: brlcad/trunk/include/bu/magic.h
===================================================================
--- brlcad/trunk/include/bu/magic.h     2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/include/bu/magic.h     2020-08-24 15:30:50 UTC (rev 76921)
@@ -218,6 +218,7 @@
 #define DB5_RAW_INTERNAL_MAGIC         0x64357269 /**< d5ri */
 #define DBI_MAGIC                      0x57204381 /**< W C? */
 #define DB_FULL_PATH_MAGIC             0x64626670 /**< dbfp */
+#define DM_MAGIC                       0x444d4d4d /**< DMMM */
 #define LIGHT_MAGIC                    0xdbddbdb7 /**< ???? */
 #define MF_MAGIC                       0x55968058 /**< U??X */
 #define PIXEL_EXT_MAGIC                0x50787400 /**< Pxt  */

Modified: brlcad/trunk/include/dm/defines.h
===================================================================
--- brlcad/trunk/include/dm/defines.h   2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/include/dm/defines.h   2020-08-24 15:30:50 UTC (rev 76921)
@@ -55,6 +55,7 @@
 /* The internals of the dm structure are hidden using the PImpl pattern*/
 struct dm_impl;
 struct dm {
+    uint32_t magic;
     struct dm_impl *i;
 };
 

Modified: brlcad/trunk/src/libdm/X/dm-X.c
===================================================================
--- brlcad/trunk/src/libdm/X/dm-X.c     2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/X/dm-X.c     2020-08-24 15:30:50 UTC (rev 76921)
@@ -477,6 +477,8 @@
 #endif
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmpi, struct dm_impl);
 
     *dmpi = *dm_X.i; /* struct copy */
@@ -2163,7 +2165,7 @@
     0                          /* Tcl interpreter */
 };
 
-struct dm dm_X = { &dm_X_impl };
+struct dm dm_X = { DM_MAGIC, &dm_X_impl };
 
 #ifdef DM_PLUGIN
 static const struct dm_plugin pinfo = { DM_API, &dm_X };

Modified: brlcad/trunk/src/libdm/dm-generic.c
===================================================================
--- brlcad/trunk/src/libdm/dm-generic.c 2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/dm-generic.c 2020-08-24 15:30:50 UTC (rev 76921)
@@ -140,6 +140,7 @@
 {
     struct dm *new_dm = DM_NULL;
     BU_GET(new_dm, struct dm);
+    new_dm->magic = DM_MAGIC;
     BU_GET(new_dm->i, struct dm_impl);
 
     /* have to manually initialize all internal structs */
@@ -392,7 +393,7 @@
 struct bu_vls *
 dm_get_pathname(struct dm *dmp)
 {
-    if (UNLIKELY(!dmp)) return NULL;
+    BU_CKMAG(dmp, DM_MAGIC, "dm internal");
     return &(dmp->i->dm_pathName);
 }
 
@@ -406,7 +407,7 @@
 struct bu_vls *
 dm_get_dname(struct dm *dmp)
 {
-    if (UNLIKELY(!dmp)) return NULL;
+    BU_CKMAG(dmp, DM_MAGIC, "dm internal");
     return &(dmp->i->dm_dName);
 }
 
@@ -420,7 +421,7 @@
 struct bu_vls *
 dm_get_tkname(struct dm *dmp)
 {
-    if (UNLIKELY(!dmp)) return NULL;
+    BU_CKMAG(dmp, DM_MAGIC, "dm internal");
     return &(dmp->i->dm_tkName);
 }
 

Modified: brlcad/trunk/src/libdm/glx/dm-ogl.c
===================================================================
--- brlcad/trunk/src/libdm/glx/dm-ogl.c 2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/glx/dm-ogl.c 2020-08-24 15:30:50 UTC (rev 76921)
@@ -718,6 +718,8 @@
     }
 
     BU_GET(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_GET(dmpi, struct dm_impl);
     *dmpi = *dm_ogl.i; /* struct copy */
     dmp->i = dmpi;
@@ -3101,7 +3103,7 @@
     0                          /* Tcl interpreter */
 };
 
-struct dm dm_ogl = { &dm_ogl_impl };
+struct dm dm_ogl = { DM_MAGIC, &dm_ogl_impl };
 
 #ifdef DM_PLUGIN
 static const struct dm_plugin pinfo = { DM_API, &dm_ogl };

Modified: brlcad/trunk/src/libdm/null/dm-Null.c
===================================================================
--- brlcad/trunk/src/libdm/null/dm-Null.c       2020-08-24 15:30:02 UTC (rev 
76920)
+++ brlcad/trunk/src/libdm/null/dm-Null.c       2020-08-24 15:30:50 UTC (rev 
76921)
@@ -38,6 +38,8 @@
     struct dm *dmp = DM_NULL;
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmp->i, struct dm_impl);
 
     *dmp->i = *dm_null.i;
@@ -402,7 +404,7 @@
     0                          /* Tcl interpreter */
 };
 
-struct dm dm_null = { &dm_null_impl };
+struct dm dm_null = { DM_MAGIC, &dm_null_impl };
 
 #ifdef DM_PLUGIN
 const struct dm_plugin pinfo = { &dm_null };

Modified: brlcad/trunk/src/libdm/osgl/dm-osgl.cpp
===================================================================
--- brlcad/trunk/src/libdm/osgl/dm-osgl.cpp     2020-08-24 15:30:02 UTC (rev 
76920)
+++ brlcad/trunk/src/libdm/osgl/dm-osgl.cpp     2020-08-24 15:30:50 UTC (rev 
76921)
@@ -441,6 +441,8 @@
     }
 
     BU_GET(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_GET(dmp->i, struct dm_impl);
 
     *dmp->i = *dm_osgl.i; /* struct copy */
@@ -2753,7 +2755,7 @@
 
 
 extern "C" {
-    struct dm dm_osgl = { &dm_osgl_impl };
+    struct dm dm_osgl = { DM_MAGIC, &dm_osgl_impl };
 
 #ifdef DM_PLUGIN
     static const struct dm_plugin pinfo = { DM_API, &dm_osgl };

Modified: brlcad/trunk/src/libdm/plot/dm-plot.c
===================================================================
--- brlcad/trunk/src/libdm/plot/dm-plot.c       2020-08-24 15:30:02 UTC (rev 
76920)
+++ brlcad/trunk/src/libdm/plot/dm-plot.c       2020-08-24 15:30:50 UTC (rev 
76921)
@@ -78,6 +78,8 @@
     Tcl_Interp *interp = (Tcl_Interp *)vinterp;
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmp->i, struct dm_impl);
 
     *dmp->i = *dm_plot.i; /* struct copy */
@@ -760,7 +762,7 @@
     NULL                       /* Tcl interpreter */
 };
 
-struct dm dm_plot = { &dm_plot_impl };
+struct dm dm_plot = { DM_MAGIC, &dm_plot_impl };
 
 #ifdef DM_PLUGIN
 const struct dm_plugin pinfo = { DM_API, &dm_plot };

Modified: brlcad/trunk/src/libdm/postscript/dm-ps.c
===================================================================
--- brlcad/trunk/src/libdm/postscript/dm-ps.c   2020-08-24 15:30:02 UTC (rev 
76920)
+++ brlcad/trunk/src/libdm/postscript/dm-ps.c   2020-08-24 15:30:50 UTC (rev 
76921)
@@ -79,6 +79,8 @@
     Tcl_Interp *interp = (Tcl_Interp *)vinterp;
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmp->i, struct dm_impl);
 
     *dmp->i = *dm_ps.i;  /* struct copy */
@@ -830,7 +832,7 @@
 };
 
 
-struct dm dm_ps = { &dm_ps_impl };
+struct dm dm_ps = { DM_MAGIC, &dm_ps_impl };
 
 #ifdef DM_PLUGIN
 const struct dm_plugin pinfo = { DM_API, &dm_ps };

Modified: brlcad/trunk/src/libdm/qt/dm-qt.cpp
===================================================================
--- brlcad/trunk/src/libdm/qt/dm-qt.cpp 2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/qt/dm-qt.cpp 2020-08-24 15:30:50 UTC (rev 76921)
@@ -341,6 +341,8 @@
     }
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmp->i, struct dm_impl);
 
     *dmp->i = *dm_qt.i; /* struct copy */
@@ -1405,7 +1407,7 @@
 
 
 extern "C" {
-    struct dm dm_qt = { &dm_qt_impl };
+    struct dm dm_qt = { DM_MAGIC, &dm_qt_impl };
 
 #ifdef DM_PLUGIN
     static const struct dm_plugin pinfo = { DM_API, &dm_qt };

Modified: brlcad/trunk/src/libdm/tk/dm-tk.c
===================================================================
--- brlcad/trunk/src/libdm/tk/dm-tk.c   2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/tk/dm-tk.c   2020-08-24 15:30:50 UTC (rev 76921)
@@ -100,6 +100,8 @@
     }
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmp_impl, struct dm_impl);
 
     *dmp_impl = *dm_tk.i; /* struct copy */
@@ -1202,7 +1204,7 @@
     0                          /* Tcl interpreter */
 };
 
-struct dm dm_tk = { &dm_tk_impl };
+struct dm dm_tk = { DM_MAGIC, &dm_tk_impl };
 
 #ifdef DM_PLUGIN
 static const struct dm_plugin pinfo = { DM_API, &dm_tk };

Modified: brlcad/trunk/src/libdm/txt/dm-txt.c
===================================================================
--- brlcad/trunk/src/libdm/txt/dm-txt.c 2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/txt/dm-txt.c 2020-08-24 15:30:50 UTC (rev 76921)
@@ -43,6 +43,8 @@
        return DM_NULL;
 
     BU_ALLOC(dmp, struct dm);
+    dmp->magic = DM_MAGIC;
+
     BU_ALLOC(dmp->i, struct dm_impl);
 
     *dmp->i = *dm_txt.i;
@@ -453,7 +455,7 @@
     0                          /* Tcl interpreter */
 };
 
-struct dm dm_txt = { &dm_txt_impl };
+struct dm dm_txt = { DM_MAGIC, &dm_txt_impl };
 
 #ifdef DM_PLUGIN
 const struct dm_plugin pinfo = { DM_API, &dm_txt };

Modified: brlcad/trunk/src/libdm/wgl/dm-wgl.c
===================================================================
--- brlcad/trunk/src/libdm/wgl/dm-wgl.c 2020-08-24 15:30:02 UTC (rev 76920)
+++ brlcad/trunk/src/libdm/wgl/dm-wgl.c 2020-08-24 15:30:50 UTC (rev 76921)
@@ -2416,6 +2416,7 @@
        }
 
        BU_ALLOC(dmp, struct dm);
+       dmp->magic = DM_MAGIC;
        BU_ALLOC(dmp->i, struct dm_impl);
 
        *dmp->i = dm_wgl_impl; /* struct copy */
@@ -2680,7 +2681,7 @@
        return dmp;
 }
 
-struct dm dm_wgl = { &dm_wgl_impl };
+struct dm dm_wgl = { DM_MAGIC, &dm_wgl_impl };
 
 #ifdef DM_PLUGIN
 static const struct dm_plugin pinfo = { DM_API, &dm_wgl };

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to