From: Erez Zadok Date: Fri, 7 Oct 2005 01:40:03 +0000 (+0000) Subject: * libamu/wire.c (print_wires): convert argument-less xsnprintf to X-Git-Tag: am-utils-6_2a1~21 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=74a57b84caa82bbc560a0e44bfbdbded1bb60ed1;p=am-utils-6.1.git * libamu/wire.c (print_wires): convert argument-less xsnprintf to xstrlcpy. * include/am_utils.h: use new HAVE_C99_VARARGS_MACROS or HAVE_GCC_VARARGS_MACROS to pass file name and line number to xsnprintf/xvsnprintf. * libamu/strutil.c (xsnprintf, xvsnprintf): if debugging is on, then also print the source file name and line number that called xsnprintf/xvsnprintf with a buffer that wasn't large enough (most likely an am-utils bug). * Makefile.am (EXTRA_DIST_M4): distribute new check_varargs_macros.m4 file. * configure.in: execute new AMU_VARARGS_MACROS test. * m4/macros/check_varargs_macros.m4: new test to check what style of variable-length argument macros, if any, does the compiler/pre-processor supports. --- diff --git a/ChangeLog b/ChangeLog index d950e65..9641636 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 2005-10-06 Erez Zadok + * libamu/wire.c (print_wires): convert argument-less xsnprintf to + xstrlcpy. + + * include/am_utils.h: use new HAVE_C99_VARARGS_MACROS or + HAVE_GCC_VARARGS_MACROS to pass file name and line number to + xsnprintf/xvsnprintf. + + * libamu/strutil.c (xsnprintf, xvsnprintf): if debugging is on, + then also print the source file name and line number that called + xsnprintf/xvsnprintf with a buffer that wasn't large enough (most + likely an am-utils bug). + + * Makefile.am (EXTRA_DIST_M4): distribute new + check_varargs_macros.m4 file. + + * configure.in: execute new AMU_VARARGS_MACROS test. + + * m4/macros/check_varargs_macros.m4: new test to check what style + of variable-length argument macros, if any, does the + compiler/pre-processor supports. + * conf/autofs/autofs_solaris_v2_v3.c (autofs_lookup_2_req) conf/autofs/autofs_solaris_v1.c (autofs_mount_1_req), amd/opts.c, amd/nfs_subr.c (nfsproc_lookup_2_svc), amd/nfs_start.c diff --git a/Makefile.am b/Makefile.am index 760dce4..e64c20e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -81,6 +81,7 @@ EXTRA_DIST_M4 = \ m4/macros/check_umount_style.m4 \ m4/macros/check_unmount_args.m4 \ m4/macros/check_unmount_call.m4 \ + m4/macros/check_varargs_macros.m4 \ m4/macros/expand_cpp_hex.m4 \ m4/macros/expand_cpp_int.m4 \ m4/macros/expand_cpp_string.m4 \ diff --git a/configure.in b/configure.in index b28e787..ff9e8da 100644 --- a/configure.in +++ b/configure.in @@ -55,7 +55,7 @@ AH_BOTTOM([ dnl dnl AC_CONFIG_AUX_DIR(m4) AC_PREREQ(2.52) -AC_REVISION($Revision: 1.118 $) +AC_REVISION($Revision: 1.119 $) AC_COPYRIGHT([Copyright (c) 1997-2005 Erez Zadok]) dnl find out system type AC_MSG_NOTICE(*** SYSTEM TYPES ***) @@ -772,6 +772,7 @@ dnl ====================================================================== dnl Generic Compiler Characteristics AC_MSG_NOTICE(*** GENERIC COMPILER CHARACTERISTICS ***) AMU_C_VOID_P +AMU_VARARGS_MACROS dnl ====================================================================== dnl ********* diff --git a/include/am_utils.h b/include/am_utils.h index 4d745a8..43a8bcd 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -333,14 +333,26 @@ extern long get_server_pid(void); extern void setup_sighandler(int signum, void (*handler)(int)); extern time_t clocktime(nfstime *nt); +#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS)) +# ifdef HAVE_C99_VARARGS_MACROS +#define xsnprintf(str,size,fmt,...) _xsnprintf(__FILE__,__LINE__,(str),(size),(fmt),__VA_ARGS__) +# endif /* HAVE_C99_VARARGS_MACROS */ +# ifdef HAVE_GCC_VARARGS_MACROS +#define xsnprintf(str,size,fmt,args...) _xsnprintf(__FILE__,__LINE__,(str),(size),(fmt),args) +# endif /* HAVE_GCC_VARARGS_MACROS */ +extern int _xsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, ...); +#define xvsnprintf(str,size,fmt,ap) _xvsnprintf(__FILE__,__LINE__,(str),(size),(fmt),(ap)) +extern int _xvsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, va_list ap); +#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ 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); +#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ #ifdef DEBUG -extern void _xstrlcat(char *dst, const char *src, size_t len, const char *filename, int lineno); -# define xstrlcat(d,s,l) _xstrlcat((d),(s),(l),__FILE__,__LINE__) -extern void _xstrlcpy(char *dst, const char *src, size_t len, const char *filename, int lineno); -# define xstrlcpy(d,s,l) _xstrlcpy((d),(s),(l),__FILE__,__LINE__) +extern void _xstrlcat(const char *filename, int lineno, char *dst, const char *src, size_t len); +# define xstrlcat(d,s,l) _xstrlcat(__FILE__,__LINE__,(d),(s),(l)) +extern void _xstrlcpy(const char *filename, int lineno, char *dst, const char *src, size_t len); +# define xstrlcpy(d,s,l) _xstrlcpy(__FILE__,__LINE__,(d),(s),(l)) #else /* not DEBUG */ extern void xstrlcat(char *dst, const char *src, size_t len); extern void xstrlcpy(char *dst, const char *src, size_t len); diff --git a/libamu/strutil.c b/libamu/strutil.c index 2405f15..17ddc7c 100644 --- a/libamu/strutil.c +++ b/libamu/strutil.c @@ -162,7 +162,7 @@ strsplit(char *s, int ch, int qc) */ void #ifdef DEBUG -_xstrlcpy(char *dst, const char *src, size_t len, const char *filename, int lineno) +_xstrlcpy(const char *filename, int lineno, char *dst, const char *src, size_t len) #else /* not DEBUG */ xstrlcpy(char *dst, const char *src, size_t len) #endif /* not DEBUG */ @@ -189,7 +189,7 @@ xstrlcpy(char *dst, const char *src, size_t len) */ void #ifdef DEBUG -_xstrlcat(char *dst, const char *src, size_t len, const char *filename, int lineno) +_xstrlcat(const char *filename, int lineno, char *dst, const char *src, size_t len) #else /* not DEBUG */ xstrlcat(char *dst, const char *src, size_t len) #endif /* not DEBUG */ @@ -211,13 +211,21 @@ xstrlcat(char *dst, const char *src, size_t len) /* our version of snprintf */ int +#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS)) +_xsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, ...) +#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ xsnprintf(char *str, size_t size, const char *format, ...) +#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ { va_list ap; int ret = 0; va_start(ap, format); +#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS)) + ret = _xvsnprintf(filename, lineno, str, size, format, ap); +#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ ret = xvsnprintf(str, size, format, ap); +#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ va_end(ap); return ret; @@ -226,7 +234,11 @@ xsnprintf(char *str, size_t size, const char *format, ...) /* our version of vsnprintf */ int +#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS)) +_xvsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, va_list ap) +#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ xvsnprintf(char *str, size_t size, const char *format, va_list ap) +#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ { int ret = 0; @@ -245,8 +257,13 @@ xvsnprintf(char *str, size_t size, const char *format, va_list ap) 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\")", +#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS)) + plog(XLOG_ERROR, "xvsnprintf(%s:%d): string %p truncated (ret=%d, format=\"%s\")", + filename, lineno, str, ret, format); +#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ + plog(XLOG_ERROR, "xvsnprintf: string %p truncated (ret=%d, format=\"%s\")", str, ret, format); +#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */ } return ret; diff --git a/libamu/wire.c b/libamu/wire.c index 2a1c44c..21d11f9 100644 --- a/libamu/wire.c +++ b/libamu/wire.c @@ -106,7 +106,7 @@ print_wires(void) return NULL; if (!localnets) { - xsnprintf(buf, buf_size, "No networks.\n"); + xstrlcpy(buf, "No networks\n", buf_size); return buf; } /* check if there's more than one network */ diff --git a/m4/macros/check_varargs_macros.m4 b/m4/macros/check_varargs_macros.m4 new file mode 100644 index 0000000..dfec692 --- /dev/null +++ b/m4/macros/check_varargs_macros.m4 @@ -0,0 +1,31 @@ +dnl ###################################################################### +dnl check if CPP can handle variable-length argument macros +AC_DEFUN([AMU_VARARGS_MACROS], +[ +AC_CACHE_CHECK(if pre-processor can handle variable-length macros, +ac_cv_varargs_macros, +[ +# try C99 style +AC_PREPROC_IFELSE( +[ +#define foo(format, ...) bar(format, __VA_ARGS__) +], ac_cv_varargs_macros=c99, +# else try gcc style +AC_PREPROC_IFELSE( +[ +#define foo(format, args...) bar(format, args) +], ac_cv_varargs_macros=gcc, ac_cv_varargs_macros=none)) +]) +if test "$ac_cv_varargs_macros" = c99 +then + AC_DEFINE(HAVE_C99_VARARGS_MACROS, 1, + [System supports C99-style variable-length argument macros]) +else + if test "$ac_cv_varargs_macros" = gcc + then + AC_DEFINE(HAVE_GCC_VARARGS_MACROS, 1, + [System supports GCC-style variable-length argument macros]) + fi +fi +]) +dnl ======================================================================