# xview-3.2_2002.patch
#
# Generated Sept. 2002 by Martin Gräfe
# (AuM.Graefe@t-online.de) to fix some bugs that - among
# other things - could lead to "Unknown client" errors.
#
# To patch the libxview enter the XView source directory
# (e.g. "xview-3.2p1.4") and type "patch -p0 < xview-3.2_2002.patch".
#
diff -ru _lib/libxview/base/xv.c lib/libxview/base/xv.c
--- _lib/libxview/base/xv.c	Fri Sep 20 20:40:42 2002
+++ lib/libxview/base/xv.c	Mon Sep 23 12:57:19 2002
@@ -46,8 +46,7 @@
 typedef         Xv_opaque(*opaque_fnp) ();
 
 /* used to automagically call initialze sv */
-static	int 	    	xv_initialized;	/* = FALSE */
-
+static	int	xv_initialized = FALSE;
 
 /* xv_alloc_save_ret is used to store an intermediate value needed by the
    xv_alloc macros. This is not necessary if the macros are implemented as
diff -ru _lib/libxview/base/xv_init.c lib/libxview/base/xv_init.c
--- _lib/libxview/base/xv_init.c	Fri Sep 20 20:40:42 2002
+++ lib/libxview/base/xv_init.c	Mon Sep 23 12:57:14 2002
@@ -35,7 +35,7 @@
 int (*xv_x_error_proc)();
 void (*xv_xlib_error_proc)();
 extern void     xv_usage();
-static int      xv_init_called;	/* = FALSE */
+static int      xv_init_called = FALSE;
 
 Xv_private void xv_init_x_pr();
 Xv_private void xv_connection_error();
@@ -44,10 +44,10 @@
 Xv_private char *xv_base_name();
 
 #ifdef OW_I18N
-Xv_private_data wchar_t *xv_app_name_wcs;
+Xv_private_data wchar_t *xv_app_name_wcs = NULL;
 #endif // /* OW_I18N */
 
-Xv_private_data char *xv_app_name;
+Xv_private_data char *xv_app_name = NULL;
 char 			*getenv();
 Xv_private_data char 	*xv_instance_app_name = NULL;
 Xv_private_data int	_xv_use_locale;
@@ -78,21 +78,21 @@
 Xv_public	Xv_object
 #ifdef ANSI_FUNC_PROTO
 xv_init(Attr_attribute attr1, ...)
-#else //
+#else
 xv_init(attr1, va_alist)
     Attr_attribute attr1;
 va_dcl
-#endif //
+#endif
 {
-    Attr_attribute     avarray[ATTR_STANDARD_SIZE];
+    Attr_attribute  avarray[ATTR_STANDARD_SIZE];
     Attr_avlist     attrs_start = avarray;
     register Attr_avlist attrs;
     va_list         valist;
     void            (*help_proc) () = xv_usage;
     int             parse_result = 0,
                     argc = 0;
-    char          **argv = (char **)NULL,
-                   *server_name = (char *) NULL;
+    char            **argv = (char **)NULL,
+                    *server_name = (char *) NULL;
     Xv_object	    server;
     extern int	    _Xdebug;
 
@@ -106,7 +106,7 @@
      xv_version_number = XV_VERSION_NUMBER;
      xv_version_string = (char *)xv_malloc(strlen(XV_VERSION_STRING) + 1);
      XV_BCOPY(XV_VERSION_STRING, xv_version_string, strlen(XV_VERSION_STRING) + 1);
-     xv_domain = xv_malloc(sizeof(XV_TEXT_DOMAIN) + 6);
+     xv_domain = xv_malloc(sizeof(XV_TEXT_DOMAIN) + 8);
     (void) sprintf(xv_domain, "%s_%04d", XV_TEXT_DOMAIN, xv_version_number);
 
     /*
@@ -314,7 +314,8 @@
 	notify_exclude_fd = ConnectionNumber((Display *)xv_get(server, XV_DISPLAY));
     }
 
-    /* Note: XSetErrorHandler must be called after the server connection
+    /*
+     * Note: XSetErrorHandler must be called after the server connection
      * has been established.  XSetErrorHandler() returns the current
      * X Error handler, which is now the defualt Xlib X Error Handler address.
      * Note: The error handler is defined by Xlib to be an int function, but
diff -ru _lib/libxview/base/xv_parse.c lib/libxview/base/xv_parse.c
--- _lib/libxview/base/xv_parse.c	Fri Sep 20 20:40:42 2002
+++ lib/libxview/base/xv_parse.c	Fri Sep 20 22:39:02 2002
@@ -497,13 +497,13 @@
 	      /* split the argv in the form of "resource:value"
 	       * into two different strings to pass into defaults_set_string
 	       */
-	      while (argv[1][i] != ':' && argv[1][i] != '\0') {
+	      while ((argv[1][i] != ':') && (argv[1][i] != '\0') && (i < 999)) {
 		      resource[i] = argv[1][i];
 		      i++;
 	      }
 	      resource[i] = '\0';
 	      if (argv[1][i] == ':') {
-		      while (argv[1][i] != '\0') {
+		      while ((argv[1][i] != '\0') && (j < 999)) {
 			      i++;
 			      value[j++] = argv[1][i];
 		      }
@@ -655,7 +655,7 @@
 /*
  * xv_merge_cmdline
  * Merges/puts the cmdline options into the passed database
- * It the passed database, does not exist yet (i.e. *db = (nil)),
+ * If the passed database, does not exist yet (i.e. *db = (nil)),
  * a new one will be created and returned.
  */
 Xv_private void
diff -ru _lib/libxview/frame/fm_cmdline.c lib/libxview/frame/fm_cmdline.c
--- _lib/libxview/frame/fm_cmdline.c	Fri Sep 20 20:40:45 2002
+++ lib/libxview/frame/fm_cmdline.c	Sun Sep 22 14:58:12 2002
@@ -247,9 +247,7 @@
 	 * Cache string obtained from defaults pkg, as it's
 	 * contents might change
 	 */
-	if (string)  {
-	    save_name = xv_strsave(string);
-	}
+	save_name = xv_strsave(string);
 
 	font = xv_find(frame_public, FONT, FONT_SET_SPECIFIER, save_name, NULL);
 	if (font)  {
@@ -260,12 +258,10 @@
 	/*
 	 * Free cached string
 	 */
-	if (save_name)  {
-	    xv_free(save_name);
-	}
+	xv_free(save_name);
     }
     defaults_set_locale(NULL, NULL);
-#else //
+#else
     if (string=xv_font_regular()) {
 	Xv_font		font;
 	char		*save_name;
@@ -274,9 +270,7 @@
 	 * Cache string obtained from defaults pkg, as it's
 	 * contents might change
 	 */
-	if (string)  {
-	    save_name = xv_strsave(string);
-	}
+	save_name = xv_strsave(string);
 
 	font = xv_find(frame_public, FONT, FONT_NAME, save_name, NULL);
 
@@ -288,9 +282,7 @@
 	/*
 	 * Free cached string
 	 */
-	if (save_name)  {
-	    xv_free(save_name);
-	}
+	xv_free(save_name);
     }
 #endif // /* OW_I18N */
 	
diff -ru _lib/libxview/notify/ntfy_test.c lib/libxview/notify/ntfy_test.c
--- _lib/libxview/notify/ntfy_test.c	Fri Sep 20 20:40:50 2002
+++ lib/libxview/notify/ntfy_test.c	Fri Sep 20 21:06:57 2002
@@ -889,7 +889,7 @@
     register char   token[100], arg1[200], arg2[200];
     int             cn = (client - &clients[0]);
 
-    n = sscanf(cond->current_action, "%s%s%s", token, arg1, arg2);
+    n = sscanf(cond->current_action, "%99s%199s%199s", token, arg1, arg2);
     if (n < 2)
 	return (-1);
     if (strcmp(token, "WRITE") == 0) {
@@ -1060,7 +1060,7 @@
     if (nt_unset_condition(client, cond))
 	return (0);
     /* Decompose action */
-    n = sscanf(cond->current_action, "%s%s%s%s%s", token, arg1, arg2, arg3,
+    n = sscanf(cond->current_action, "%99s%199s%199s%199s%199s", token, arg1, arg2, arg3,
 	       arg4);
     /* Skip blank actions */
     if (n < 1)
@@ -1255,7 +1255,7 @@
     int             pidchild, n;
 
     /* Reparse line to get all extra args into arg2 */
-    n = sscanf(cond->current_action, "%s%s%[^\n]", token, arg1, arg2);
+    n = sscanf(cond->current_action, "%99s%199s%199[^\n]", token, arg1, arg2);
     (void) nt_constructargs(args, arg1, arg2, ARGS_MAX);
     /* Fork progam */
     pidchild = fork();
@@ -1296,7 +1296,7 @@
     }
     if (cond->current_condition == NULL)
 	goto Done;
-    n = sscanf(cond->current_condition, "%s", token);
+    n = sscanf(cond->current_condition, "%99s", token);
     if (n < 1)
 	goto BadCond;
     if (strcmp(token, "INPUT") == 0) {
@@ -1377,7 +1377,7 @@
 	/* Current condition may be null */
 	if (cond->current_condition == NULL)
 	    continue;
-	n = sscanf(cond->current_condition, "%s", name);
+	n = sscanf(cond->current_condition, "%99s", name);
 	if (n == 1 && strcmp(token, name) == 0) {
 	    if (use) {
 		if (cond->data.i != data) {
@@ -1435,7 +1435,7 @@
 	  case 's':		/* Set Unix event generation speed */
 	    if (argc < 2)
 		goto ArgNum;
-	    if (sscanf(argv[1], "%hs", tmp) != 1)
+	    if (sscanf(argv[1], "%99s", tmp) != 1)
 		goto ArgFormat;
 	    if (strcmp(tmp, "fast") == 0)
 		generation_speed = FAST;
@@ -1450,7 +1450,7 @@
 	  case 'i':		/* Client on stack method */
 	    if (argc < 2)
 		goto ArgNum;
-	    if (sscanf(argv[1], "%hs", tmp) != 1)
+	    if (sscanf(argv[1], "%99s", tmp) != 1)
 		goto ArgFormat;
 	    if (strcmp(tmp, "none") == 0)
 		input_method = NONE;
@@ -1465,7 +1465,7 @@
 	  case 'c':		/* Client specification */
 	    if (argc < 2)
 		goto ArgNum;
-	    if (sscanf(argv[1], "%hs", tmp) != 1)
+	    if (sscanf(argv[1], "%99s", tmp) != 1)
 		goto ArgFormat;
 	    if (nt_get_client(tmp) == -1)
 		goto Help;
@@ -1474,7 +1474,7 @@
 	  case 'x':		/* Acting as exerciser process */
 	    if (argc < 2)
 		goto ArgNum;
-	    if (sscanf(argv[1], "%hs", tmp) != 1)
+	    if (sscanf(argv[1], "%99s", tmp) != 1)
 		goto ArgFormat;
 	    if (strcmp(tmp, "wait3") == 0)
 		wait3er = 1;
@@ -1570,7 +1570,7 @@
 	    return (-1);
 	}
 	/* Pick off next line */
-	switch (n = sscanf(s, "%s%[^\n]\n", token, args)) {
+	switch (n = sscanf(s, "%99s%199[^\n]\n", token, args)) {
 	  case EOF:		/* End of input string */
 	    goto Done;
 	  case 0:		/* Blank line */
diff -ru _lib/libxview/server/svr_parse.c lib/libxview/server/svr_parse.c
--- _lib/libxview/server/svr_parse.c	Fri Sep 20 20:40:44 2002
+++ lib/libxview/server/svr_parse.c	Fri Sep 20 22:06:28 2002
@@ -440,12 +440,12 @@
 #endif // /* OW_I18N */
 	( resourceString, XV_PROC_CODE("coreset"), STRLEN(XV_PROC_CODE("coreset"))) ) {
 
-	char funcname[100], resname[100];
+	char funcname[100], resname[130];
 	XrmValue value;
 	char *strtype;
 
 	*funcname = '\0';
-	SSCANF( resourceString, "%*s%s", funcname );
+	SSCANF( resourceString, "%*s%99s", funcname );
 
 	/*
 	 * Put resource name in multibyte buffer to pass to XrmGetResource()
