xaw3d (1.5+E-18) lib/Xaw3d/TextPop.c

Summary

 lib/Xaw3d/TextPop.c |   71 +++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 60 insertions(+), 11 deletions(-)

    
download this patch

Patch contents

--- xaw3d-1.5+E.orig/lib/Xaw3d/TextPop.c
+++ xaw3d-1.5+E/lib/Xaw3d/TextPop.c
@@ -66,6 +66,8 @@
 #include <X11/Xos.h>		/* for O_RDONLY */
 #include <errno.h>
 
+#include "XawAlloc.h"
+
 #ifdef X_NOT_STDC_ENV
 extern int errno;
 #endif
@@ -809,6 +811,8 @@
 struct SearchAndReplace * search;
 {
   char msg[BUFSIZ];
+  char *pmsg;
+  int len;
   Widget tw = XtParent(search->search_popup);
   XawTextPosition pos;
   XawTextScanDirection dir;
@@ -835,9 +839,20 @@
    /* The Raw string in find.ptr may be WC I can't use here, so I re - call 
    GetString to get a tame version. */
 
-  if (pos == XawTextSearchError) 
-    (void) sprintf( msg, "Could not find string ``%s''.", GetString( search->search_text ) );
-  else {
+  if (pos == XawTextSearchError) {
+    char *msg1 = "Could not find string ``";
+    char *msg2 = "''.";
+    len = strlen(msg1) + strlen(msg2) +
+		strlen(GetString( search->search_text )) + 1;
+    pmsg = XtStackAlloc(len, msg);
+    if (pmsg != NULL) {
+      (void) sprintf( pmsg, "%s%s%s", msg1, GetString( search->search_text ),
+			msg2);
+    } else {
+      pmsg = msg;
+      (void) sprintf( pmsg, "Could not find string");
+    }
+  } else {
     if (dir == XawsdRight)
       XawTextSetInsertionPoint( tw, pos + text.length);
     else
@@ -849,7 +864,8 @@
   }
   
   XawTextUnsetSelection(tw);
-  SetSearchLabels(search, msg, "", TRUE);
+  SetSearchLabels(search, pmsg, "", TRUE);
+  XtStackFree(pmsg, msg);
   return(FALSE);
 }
 
@@ -982,13 +998,26 @@
       if ( (new_pos == XawTextSearchError) ) {
 	if (count == 0) {
 	  char msg[BUFSIZ];
+	  char *pmsg;
+	  int len;
+	  char *msg1 = "*** Error: Could not find string ``";
+	  char *msg2 = "''. ***";
 
              /* The Raw string in find.ptr may be WC I can't use here, 
 		so I call GetString to get a tame version.*/
 
-	  (void) sprintf( msg, "%s %s %s", "*** Error: Could not find string ``",
-		  GetString( search->search_text ), "''. ***");
-	  SetSearchLabels(search, msg, "", TRUE);
+	  len = strlen(msg1) + strlen(msg2) +
+		strlen(GetString( search->search_text )) + 1;
+	  pmsg = XtStackAlloc(len, msg);
+	  if (pmsg != NULL) {
+	    (void) sprintf( pmsg, "%s%s%s", msg1,
+				GetString( search->search_text ), msg2);
+	  } else {
+	    pmsg = msg;
+	    (void) sprintf(pmsg, "*** Error: Could not find string ***");
+	  }
+	  SetSearchLabels(search, pmsg, "", TRUE);
+	  XtStackFree(pmsg, msg);
 	  return(FALSE);
 	}
 	else
@@ -1011,9 +1040,22 @@
 
     if (XawTextReplace(tw, pos, end_pos, &replace) != XawEditDone) {
       char msg[BUFSIZ];
-      
-      (void) sprintf( msg, "'%s' with '%s'. ***", find.ptr, replace.ptr);
+      char *pmsg;
+      int len;
+      char *msg1 = "' with '";
+      char *msg2 = "'. ***";
+
+      len = 1 + strlen(msg1) + strlen(msg2) + strlen(find.ptr) +
+		strlen(replace.ptr) + 1;
+      pmsg = XtStackAlloc(len, msg);
+      if (pmsg != NULL) {
+	(void) sprintf( pmsg, "`%s%s%s%s", find.ptr, msg1, replace.ptr, msg2);
+      } else {
+	pmsg = msg;
+	(void) sprintf(pmsg, "string ***");
+      }
       SetSearchLabels(search, "*** Error while replacing", msg, TRUE);
+      XtStackFree(pmsg, msg);
       return(FALSE);
     }      
 
@@ -1164,13 +1206,20 @@
 {
   Widget temp_widget;
   char buf[BUFSIZ];
+  char *pbuf;
+  int len;
 
-  (void) sprintf(buf, "%s.%s", FORM_NAME, name);
+  len = strlen(FORM_NAME) + strlen(name) + 2;
+  pbuf = XtStackAlloc(len, buf);
+  if (pbuf == NULL) return FALSE;
+  (void) sprintf(pbuf, "%s.%s", FORM_NAME, name);
 
-  if ( (temp_widget = XtNameToWidget(shell, buf)) != NULL) {
+  if ( (temp_widget = XtNameToWidget(shell, pbuf)) != NULL) {
     SetResource(temp_widget, res_name, value);
+    XtStackFree(pbuf, buf);
     return(TRUE);
   }
+  XtStackFree(pbuf, buf);
   return(FALSE);
 }