pfsglview crashes [patch]

15 views
Skip to first unread message

Michael Paul

unread,
Apr 20, 2017, 3:32:07 AM4/20/17
to pfstools
After compiling pfstools 2.0.6 from source on macOS 10.12.4, I found that pfsglview sometimes crashes at startup, right after creating its window.  I did some debugging and found that the crash happens because SC_Status::redraw() is using the "mappingMode", "channel", and "navigationMode" pointers (in a call to sprintf) before they've been initialized.  Dereferencing the uninitialized pointers sometimes causes a segmentation fault.

Those three variables are set by the updateStatus() function in pfsglview.cpp, but updateStatus() isn't called before the window is first drawn.  The only calls to it are in various GLUT listener functions that respond to user actions, and in updateMapping_thread() which runs asynchronously.

This patch prevents the crash by ensuring that the status strings are initialized before they're displayed:

--- pfsglview.cpp.orig    2017-03-15 08:42:45.000000000 -0400
+++ pfsglview.cpp    2017-04-20 00:17:34.000000000 -0400
@@ -1763,6 +1763,8 @@
     m_osd_loading
= new M_OnScreenDisplay(loadtext, sizeof( loadtext ) / sizeof( loadtext[0] ) );
     m_osd_mapping
= new M_OnScreenDisplay(maptext, sizeof( maptext ) / sizeof( maptext[0] ) );
 
+    updateStatus();
+
     glutInit
(&argc, argv);
     glutInitWindowPosition
(0.1 * glutGet(GLUT_SCREEN_WIDTH), 0.1 * glutGet(GLUT_SCREEN_HEIGHT));
     glutInitWindowSize
(0.8 * glutGet(GLUT_SCREEN_WIDTH), 0.8 * glutGet(GLUT_SCREEN_HEIGHT));



Rafal

unread,
Jun 3, 2017, 5:03:31 AM6/3/17
to pfstools
Thanks. The patch is in the git repository and will be included in 2.0.7.

Rafal


Reply all
Reply to author
Forward
0 new messages