* libamu/xutil.c (real_plog, xsnprintf): call new xvsnprintf()
authorErez Zadok <ezk@cs.sunysb.edu>
Sun, 14 Aug 2005 20:01:13 +0000 (20:01 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Sun, 14 Aug 2005 20:01:13 +0000 (20:01 +0000)
wrapper function.
(xvsnprintf): new function which already gets a va_list.  This was
needed to avoid nesting va_list's (which apparently isn't
allowed).

* include/am_utils.h: prototype for new xvsnprintf wrapper.

ChangeLog
include/am_utils.h
libamu/xutil.c

index 3fbd7f5a709b42af3851e6e634e3b6e7698ed5ed..1b8d7c58fe9a03aae90c38fc4e6bbb9bf79eba73 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-08-14  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * libamu/xutil.c (real_plog, xsnprintf): call new xvsnprintf()
+       wrapper function.
+       (xvsnprintf): new function which already gets a va_list.  This was
+       needed to avoid nesting va_list's (which apparently isn't
+       allowed).
+
+       * include/am_utils.h: prototype for new xvsnprintf wrapper.
+
        * configure.in: sinclude([vers.m4]) version number file.
 
        * vers.m4: new file to separate version number out of
index 092cda7c9a59a56c4322fee74daf43454766277a..f11e08871e9dab0b28b4fdf32d139fe9e50f42a7 100644 (file)
@@ -334,6 +334,7 @@ extern int check_pmap_up(char *host, struct sockaddr_in* sin);
 extern u_long get_nfs_version(char *host, struct sockaddr_in *sin, u_long nfs_version, const char *proto);
 extern long get_server_pid(void);
 extern int xsnprintf(char *str, size_t size, const char *format, ...);
+extern int xvsnprintf(char *str, size_t size, const char *format, va_list ap);
 extern void setup_sighandler(int signum, void (*handler)(int));
 
 
index b9ce2469cb35ab3531a42ae13135e7ab1c5953bc..bd87a6b81580742754e95bab240f2c9f3473e29e 100644 (file)
@@ -439,11 +439,11 @@ real_plog(int lvl, const char *fmt, va_list vargs)
 #endif /* DEBUG_MEM */
 
   /*
-   * Note: xsnprintf() may call plog() if a truncation happened, but the
+   * Note: xvsnprintf() may call plog() if a truncation happened, but the
    * latter has some code to break out of an infinite loop.  See comment in
    * xsnprintf() below.
    */
-  xsnprintf(ptr, 1023, expand_error(fmt, efmt, 1024), vargs);
+  xvsnprintf(ptr, 1023, expand_error(fmt, efmt, 1024), vargs);
 
   ptr += strlen(ptr);
   if (*(ptr-1) == '\n')
@@ -961,25 +961,38 @@ xsnprintf(char *str, size_t size, const char *format, ...)
   int ret = 0;
 
   va_start(ap, format);
+  ret = xvsnprintf(str, size, format, ap);
+  va_end(ap);
+
+  return ret;
+}
+
+
+/* our version of vsnprintf */
+int
+xvsnprintf(char *str, size_t size, const char *format, va_list ap)
+{
+  int ret = 0;
+
 #ifdef HAVE_VSNPRINTF
   ret = vsnprintf(str, size, format, ap);
 #else /* not HAVE_VSNPRINTF */
   ret = vsprintf(str, format, ap); /* less secure version */
 #endif /* not HAVE_VSNPRINTF */
-  va_end(ap);
   /*
    * If error or truncation, plog error.
    *
    * WARNING: we use the static 'maxtrunc' variable below to break out any
-   * possible infinite recursion between plog() and xsnprintf().  If it ever
-   * happens, it'd indicate a bug in Amd.
+   * possible infinite recursion between plog() and xvsnprintf().  If it
+   * ever happens, it'd indicate a bug in Amd.
    */
-  if (ret < 0 || (size_t) ret >= size) { /* error or truncation occured */
-    static int maxtrunc;       /* hack to avoid inifinite loop */
+  if (ret < 0 || ret >= size) { /* error or truncation occured */
+    static int maxtrunc;        /* hack to avoid inifinite loop */
     if (++maxtrunc > 10)
       plog(XLOG_ERROR, "BUG: string %p truncated (ret=%d, format=\"%s\")",
-          str, ret, format);
+           str, ret, format);
   }
+
   return ret;
 }