Revision: 75633
          http://sourceforge.net/p/brlcad/code/75633
Author:   starseeker
Date:     2020-04-29 17:26:37 +0000 (Wed, 29 Apr 2020)
Log Message:
-----------
Check to make sure our XY coordinate hasn't gotten beyond our buffer size - can 
happen right at the end.

Modified Paths:
--------------
    brlcad/trunk/src/libdm/tests/tcl_img.cpp

Modified: brlcad/trunk/src/libdm/tests/tcl_img.cpp
===================================================================
--- brlcad/trunk/src/libdm/tests/tcl_img.cpp    2020-04-29 16:35:02 UTC (rev 
75632)
+++ brlcad/trunk/src/libdm/tests/tcl_img.cpp    2020-04-29 17:26:37 UTC (rev 
75633)
@@ -211,7 +211,7 @@
 }
 
 int
-image_paint_xy(ClientData UNUSED(clientData), Tcl_Interp *interp, int argc, 
char **argv)
+image_paint_xy(ClientData clientData, Tcl_Interp *interp, int argc, char 
**argv)
 {
     if (argc != 3) {
        std::cerr << "Unexpected argc: " << argc << "\n";
@@ -218,6 +218,8 @@
        return TCL_ERROR;
     }
 
+    struct img_data *idata = (struct img_data *)clientData;
+
     // Unpack the coordinates (checking errno, although it may not truly be
     // necessary if we trust Tk to always give us valid coordinates...)
     char *p_end;
@@ -245,6 +247,9 @@
     for (int i = -2; i < 3; i++) {
        for (int j = -2; j < 3; j++) {
            int pindex = img_xy_index(dm_data.width, dm_data.height, xcoor, 
ycoor, i, j);
+           if (pindex >= idata->buff_size - 1) {
+               continue;
+           }
            // Set to opaque white
            dm_data.pixelPtr[pindex] = 255;
            dm_data.pixelPtr[pindex+1] = 255;
@@ -534,7 +539,7 @@
 
 
     // Register a paint command so we can change the image contents near the 
cursor position
-    (void)Tcl_CreateCommand(interp, "image_paint", (Tcl_CmdProc 
*)image_paint_xy, NULL, (Tcl_CmdDeleteProc* )NULL);
+    (void)Tcl_CreateCommand(interp, "image_paint", (Tcl_CmdProc 
*)image_paint_xy, (ClientData)idata, (Tcl_CmdDeleteProc* )NULL);
     // Establish the Button-1+Motion combination event as the trigger for 
drawing on the image
     bind_cmd = std::string("bind . <B1-Motion> {image_paint %x %y}");
     Tcl_Eval(interp, bind_cmd.c_str());

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