ncurses 5.9 - patch 20121215
[ncurses.git] / ncurses / trace / lib_tracemse.c
index e062a26af52371c2352287999c89bf35cb890f3a..51ffa2ef7634884bf02816032ddbbc548c09b301 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: lib_tracemse.c,v 1.20 2012/02/22 22:40:24 tom Exp $")
+MODULE_ID("$Id: lib_tracemse.c,v 1.21 2012/12/15 23:51:19 tom Exp $")
 
 #ifdef TRACE
 
@@ -114,24 +114,33 @@ _trace_mmask_t(SCREEN *sp, mmask_t code)
 NCURSES_EXPORT(char *)
 _nc_tracemouse(SCREEN *sp, MEVENT const *ep)
 {
-    _nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
-               TRACEMSE_FMT,
-               ep->id,
-               ep->x,
-               ep->y,
-               ep->z,
-               (unsigned long) ep->bstate);
-
-    (void) _trace_mmask_t(sp, ep->bstate);
-    _nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
-    return (my_buffer);
+    char *result = 0;
+
+    if (sp != 0) {
+       _nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
+                   TRACEMSE_FMT,
+                   ep->id,
+                   ep->x,
+                   ep->y,
+                   ep->z,
+                   (unsigned long) ep->bstate);
+
+       (void) _trace_mmask_t(sp, ep->bstate);
+       _nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
+       result = (my_buffer);
+    }
+    return result;
 }
 
 NCURSES_EXPORT(mmask_t)
 _nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
 {
-    *my_buffer = '\0';
-    T((T_RETURN("{%s}"), _trace_mmask_t(sp, code)));
+    if (sp != 0) {
+       *my_buffer = '\0';
+       T((T_RETURN("{%s}"), _trace_mmask_t(sp, code)));
+    } else {
+       T((T_RETURN("{?}")));
+    }
     return code;
 }