mej pushed a commit to branch master.
commit 9d0be7b7d259415771e22565fe29bafe52df3606
Author: Michael Jennings <[email protected]>
Date: Tue Mar 5 12:58:01 2013 -0800
Updated the autotools stuff some. Bumped version to 0.8.
Reformatted some macros in libast.h.
Fixed the sprintf() methods of the str, ustr, and mbuff classes.
Added check for compiler support of compound statement expressions.
Fixed a spec file bug.
---
Makefile.am | 1 +
autogen.sh | 78 ++++++++++++++---------------
configure.ac | 47 ++----------------
include/libast.h | 148 ++++++++++++++++++++++++++++++++++++++++++++-----------
libast.m4 | 35 +++++++++++--
libast.spec | 2 +-
src/mbuff.c | 21 +++++---
src/str.c | 24 ++++++---
src/ustr.c | 24 ++++++---
9 files changed, 244 insertions(+), 136 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 37e3d9b..162cd50 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
# $Id$
AUTOMAKE_OPTIONS = foreign
+ACLOCAL_AMFLAGS = -I .
SUBDIRS = include src test
bin_SCRIPTS = libast-config
diff --git a/autogen.sh b/autogen.sh
index afe9439..50f8b78 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -20,53 +20,53 @@ DIE=0
echo "Generating configuration files for libast, please wait...."
-LIBTOOLIZE_CHOICES="$LIBTOOLIZE libtoolize glibtoolize"
-ACLOCAL_CHOICES="$ACLOCAL aclocal"
-AUTOCONF_CHOICES="$AUTOCONF autoconf"
-AUTOHEADER_CHOICES="$AUTOHEADER autoheader"
-AUTOMAKE_CHOICES="$AUTOMAKE automake"
+if autoreconf -V >/dev/null 2>&1 ; then
+ set -x
+ autoreconf -f -i
+else
+ LIBTOOLIZE_CHOICES="$LIBTOOLIZE libtoolize glibtoolize"
+ ACLOCAL_CHOICES="$ACLOCAL aclocal"
+ AUTOCONF_CHOICES="$AUTOCONF autoconf"
+ AUTOHEADER_CHOICES="$AUTOHEADER autoheader"
+ AUTOMAKE_CHOICES="$AUTOMAKE automake"
-for i in $LIBTOOLIZE_CHOICES ; do
- $i --version </dev/null >/dev/null 2>&1 && LIBTOOLIZE=$i && break
-done
-[ "x$LIBTOOLIZE" = "x" ] && broken libtool
+ for i in $LIBTOOLIZE_CHOICES ; do
+ $i --version </dev/null >/dev/null 2>&1 && LIBTOOLIZE=$i && break
+ done
+ [ "x$LIBTOOLIZE" = "x" ] && broken libtool
-for i in $ACLOCAL_CHOICES ; do
- $i --version </dev/null >/dev/null 2>&1 && ACLOCAL=$i && break
-done
-[ "x$ACLOCAL" = "x" ] && broken automake
+ for i in $ACLOCAL_CHOICES ; do
+ $i --version </dev/null >/dev/null 2>&1 && ACLOCAL=$i && break
+ done
+ [ "x$ACLOCAL" = "x" ] && broken automake
-for i in $AUTOCONF_CHOICES ; do
- $i --version </dev/null >/dev/null 2>&1 && AUTOCONF=$i && break
-done
-[ "x$AUTOCONF" = "x" ] && broken autoconf
+ for i in $AUTOCONF_CHOICES ; do
+ $i --version </dev/null >/dev/null 2>&1 && AUTOCONF=$i && break
+ done
+ [ "x$AUTOCONF" = "x" ] && broken autoconf
-for i in $AUTOHEADER_CHOICES ; do
- $i --version </dev/null >/dev/null 2>&1 && AUTOHEADER=$i && break
-done
-[ "x$AUTOHEADER" = "x" ] && broken autoconf
+ for i in $AUTOHEADER_CHOICES ; do
+ $i --version </dev/null >/dev/null 2>&1 && AUTOHEADER=$i && break
+ done
+ [ "x$AUTOHEADER" = "x" ] && broken autoconf
-for i in $AUTOMAKE_CHOICES ; do
- $i --version </dev/null >/dev/null 2>&1 && AUTOMAKE=$i && break
-done
-[ "x$AUTOMAKE" = "x" ] && broken automake
+ for i in $AUTOMAKE_CHOICES ; do
+ $i --version </dev/null >/dev/null 2>&1 && AUTOMAKE=$i && break
+ done
+ [ "x$AUTOMAKE" = "x" ] && broken automake
-# Export them so configure can AC_SUBST() them.
-export LIBTOOLIZE ACLOCAL AUTOCONF AUTOHEADER AUTOMAKE
+ # Export them so configure can AC_SUBST() them.
+ export LIBTOOLIZE ACLOCAL AUTOCONF AUTOHEADER AUTOMAKE
-# Check for existing libast.m4 we can use. Use the local one if not.
-#if test ! -f "`$ACLOCAL --print-ac-dir`/libast.m4"; then
- ACLOCAL_FLAGS="-I . $ACLOCAL_FLAGS"
-#fi
-
-# Run the stuff.
-(set -x && $LIBTOOLIZE -c -f) || abort libtool
-(set -x && $ACLOCAL $ACLOCAL_FLAGS) || abort aclocal
-(set -x && $AUTOCONF) || abort autoconf
-(set -x && $AUTOHEADER) || abort autoheader
-(set -x && $AUTOMAKE -a -c) || abort automake
+ # Run the stuff.
+ (set -x && $LIBTOOLIZE -c -f) || abort libtool
+ (set -x && $ACLOCAL) || abort aclocal
+ (set -x && $AUTOCONF) || abort autoconf
+ (set -x && $AUTOHEADER) || abort autoheader
+ (set -x && $AUTOMAKE -a -c) || abort automake
+fi
# Run configure.
if test x"$NOCONFIGURE" = x; then
-(set -x && ./configure "$@")
+ (set -x && ./configure "$@")
fi
diff --git a/configure.ac b/configure.ac
index 633504e..8e6bfb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,54 +1,16 @@
-dnl# $Id$
-
-test "x$LIBTOOLIZE" = "x" && LIBTOOLIZE=libtoolize
-test "x$ACLOCAL" = "x" && ACLOCAL=aclocal
-test "x$AUTOCONF" = "x" && AUTOCONF=autoconf
-test "x$AUTOHEADER" = "x" && AUTOHEADER=autoheader
-test "x$AUTOMAKE" = "x" && AUTOMAKE=automake
-
-AC_SUBST(LIBTOOLIZE)
-AC_SUBST(ACLOCAL)
-AC_SUBST(AUTOCONF)
-AC_SUBST(AUTOHEADER)
-AC_SUBST(AUTOMAKE)
-
-SAVE_LIBTOOLIZE="$LIBTOOLIZE"
-SAVE_ACLOCAL="$ACLOCAL"
-SAVE_AUTOCONF="$AUTOCONF"
-SAVE_AUTOHEADER="$AUTOHEADER"
-SAVE_AUTOMAKE="$AUTOMAKE"
+# $Id$
AC_INIT(configure.ac)
-AM_INIT_AUTOMAKE(libast, 0.7.1)
+AM_INIT_AUTOMAKE([libast], [0.8])
AC_DEFINE_UNQUOTED(LIBAST_VERSION, "$VERSION", [Version])
-AC_CONFIG_HEADERS(config.h include/libast/sysdefs.h)
-
-LIBTOOLIZE="${SAVE_LIBTOOLIZE:-libtoolize}"
-ACLOCAL="${SAVE_ACLOCAL:-aclocal}"
-AUTOCONF="${SAVE_AUTOCONF:-autoconf}"
-AUTOHEADER="${SAVE_AUTOHEADER:-autoheader}"
-AUTOMAKE="${SAVE_AUTOMAKE:-automake}"
-
-AC_MSG_CHECKING(for preferred libtoolize)
-AC_MSG_RESULT($LIBTOOLIZE)
-AC_MSG_CHECKING(for preferred aclocal)
-AC_MSG_RESULT($ACLOCAL)
-AC_MSG_CHECKING(for preferred autoconf)
-AC_MSG_RESULT($AUTOCONF)
-AC_MSG_CHECKING(for preferred autoheader)
-AC_MSG_RESULT($AUTOHEADER)
-AC_MSG_CHECKING(for preferred automake)
-AC_MSG_RESULT($AUTOMAKE)
+AC_CONFIG_HEADERS([config.h include/libast/sysdefs.h])
+AC_CONFIG_MACRO_DIR([.])
dnl# Set some basic variables
AUTHORS="Michael Jennings ([email protected])"
AC_SUBST(AUTHORS)
AC_DEFINE_UNQUOTED(AUTHORS, "$AUTHORS", [Authors])
-AC_CANONICAL_BUILD()
-AC_CANONICAL_HOST()
-AC_CANONICAL_TARGET()
-
AC_PROG_CC
AC_PROG_CPP
@@ -58,6 +20,7 @@ AST_VAR_CHECKS()
AST_HEADER_CHECKS()
AST_TYPE_CHECKS()
AST_FUNC_CHECKS()
+AST_COMPILER_CHECKS()
AC_PROG_LIBTOOL()
diff --git a/include/libast.h b/include/libast.h
index fc6eaff..8d243f1 100644
--- a/include/libast.h
+++ b/include/libast.h
@@ -515,43 +515,135 @@ extern int re_exec();
#if DEBUG >= 1
# if defined(__FILE__) && defined(__LINE__)
# ifdef __GNUC__
-# define ASSERT(x) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__,
__FILE__, __LINE__, #x);} \
- else
{libast_print_warning("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__,
__FILE__, __LINE__, #x); return;}}} while (0)
-# define ASSERT_RVAL(x, val) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__,
__FILE__, __LINE__, #x);} \
- else
{libast_print_warning("ASSERT failed in %s() at %s:%d: %s\n", __FUNCTION__,
__FILE__, __LINE__, #x);} \
- return (val);}} while (0)
-# define ASSERT_NOTREACHED() do {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed in %s() at %s:%d: This code should not be
reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
- else
{libast_print_warning("ASSERT failed in %s() at %s:%d: This code should not be
reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
- } while (0)
-# define ASSERT_NOTREACHED_RVAL(val) do {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed in %s() at %s:%d: This code should not be
reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
- else
{libast_print_warning("ASSERT failed in %s() at %s:%d: This code should not be
reached.\n", __FUNCTION__, __FILE__, __LINE__);} \
- return (val);} while (0)
+# define ASSERT(x) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed in %s() at
%s:%d: %s\n", \
+ __FUNCTION__, __FILE__,
__LINE__, #x); \
+ } else { \
+ libast_print_warning("ASSERT failed in %s()
at %s:%d: %s\n", \
+ __FUNCTION__, __FILE__,
__LINE__, #x); \
+ return; \
+ } \
+ } \
+ } while (0)
+# define ASSERT_RVAL(x, val) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed
in %s() at %s:%d: %s\n", \
+ __FUNCTION__,
__FILE__, __LINE__, #x); \
+ } else { \
+ libast_print_warning("ASSERT
failed in %s() at %s:%d: %s\n", \
+ __FUNCTION__,
__FILE__, __LINE__, #x); \
+ return (val); \
+ } \
+ } \
+ } while (0)
+# define ASSERT_NOTREACHED() \
+ do { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed in %s() at %s:%d: This code
should not be reached.\n", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ } else { \
+ libast_print_warning("ASSERT failed in %s() at %s:%d: This
code should not be reached.\n", \
+ __FUNCTION__, __FILE__, __LINE__);} \
+ } while (0)
+# define ASSERT_NOTREACHED_RVAL(val) \
+ do { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed in %s() at %s:%d: This code
should not be reached.\n", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ } else { \
+ libast_print_warning("ASSERT failed in %s() at %s:%d: This
code should not be reached.\n", \
+ __FUNCTION__, __FILE__, __LINE__); \
+ } \
+ return (val); \
+ } while (0)
# define ABORT() libast_fatal_error("Aborting in %s() at %s:%d.\n",
__FUNCTION__, __FILE__, __LINE__)
# else
-# define ASSERT(x) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x);} \
- else
{libast_print_warning("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x);
return;}}} while (0)
-# define ASSERT_RVAL(x, val) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__, #x);} \
- else
{libast_print_warning("ASSERT failed at %s:%d: %s\n", __FILE__, __LINE__,
#x);} \
- return (val);}} while (0)
-# define ASSERT_NOTREACHED() do {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed at %s:%d: This code should not be
reached.\n", __FILE__, __LINE__);} \
- else
{libast_print_warning("ASSERT failed at %s:%d: This code should not be
reached.\n", __FILE__, __LINE__);} \
- } while (0)
-# define ASSERT_NOTREACHED_RVAL(val) do {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed at %s:%d: This code should not be
reached.\n", __FILE__, __LINE__);} \
- else
{libast_print_warning("ASSERT failed at %s:%d: This code should not be
reached.\n", __FILE__, __LINE__);} \
- return (val);} while (0)
+# define ASSERT(x) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed at %s:%d:
%s\n", __FILE__, __LINE__, #x); \
+ } else { \
+ libast_print_warning("ASSERT failed at
%s:%d: %s\n", __FILE__, __LINE__, #x); \
+ return; \
+ } \
+ } \
+ } while (0)
+# define ASSERT_RVAL(x, val) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed
at %s:%d: %s\n", __FILE__, __LINE__, #x); \
+ } else { \
+ libast_print_warning("ASSERT
failed at %s:%d: %s\n", __FILE__, __LINE__, #x); \
+ } \
+ return (val); \
+ } \
+ } while (0)
+# define ASSERT_NOTREACHED() do { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed at
%s:%d: This code should not be reached.\n", \
+ __FILE__,
__LINE__); \
+ } else { \
+ libast_print_warning("ASSERT failed at
%s:%d: This code should not be reached.\n", \
+ __FILE__,
__LINE__); \
+ } \
+ } while (0)
+# define ASSERT_NOTREACHED_RVAL(val) \
+ do { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed at %s:%d: This code should
not be reached.\n", __FILE__, __LINE__); \
+ } else { \
+ libast_print_warning("ASSERT failed at %s:%d: This code
should not be reached.\n", __FILE__, __LINE__); \
+ } \
+ return (val); \
+ } while (0)
# define ABORT() libast_fatal_error("Aborting at %s:%d.\n", __FILE__,
__LINE__)
# endif
# else
-# define ASSERT(x) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed: %s\n", #x);} \
- else
{libast_print_warning("ASSERT failed: %s\n", #x); return;}}} while (0)
-# define ASSERT_RVAL(x, val) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{libast_fatal_error("ASSERT failed: %s\n", #x);} \
- else
{libast_print_warning("ASSERT failed: %s\n", #x);} return (val);}} while (0)
+# define ASSERT(x) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed: %s\n",
#x); \
+ } else { \
+ libast_print_warning("ASSERT failed: %s\n",
#x); \
+ return; \
+ } \
+ } \
+ } while (0)
+# define ASSERT_RVAL(x, val) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ libast_fatal_error("ASSERT failed:
%s\n", #x); \
+ } else { \
+ libast_print_warning("ASSERT
failed: %s\n", #x); \
+ } \
+ return (val); \
+ } \
+ } while (0)
# define ASSERT_NOTREACHED() return
# define ASSERT_NOTREACHED_RVAL(x) return (x)
# define ABORT() libast_fatal_error("Aborting.\n")
# endif
-# define REQUIRE(x) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{__DEBUG(); libast_dprintf("REQUIRE failed: %s\n", #x);} return;}} while (0)
-# define REQUIRE_RVAL(x, v) do {if (!(x)) {if (DEBUG_LEVEL>=1)
{__DEBUG(); libast_dprintf("REQUIRE failed: %s\n", #x);} return (v);}} while
(0)
+# define REQUIRE(x) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ __DEBUG(); \
+ libast_dprintf("REQUIRE
failed: %s\n", #x); \
+ } \
+ return; \
+ } \
+ } while (0)
+# define REQUIRE_RVAL(x, v) do { \
+ if (!(x)) { \
+ if (DEBUG_LEVEL >= 1) { \
+ __DEBUG(); \
+ libast_dprintf("REQUIRE
failed: %s\n", #x); \
+ } \
+ return (v); \
+ } \
+ } while (0)
#else
# define ASSERT(x) NOP
# define ASSERT_RVAL(x, val) NOP
diff --git a/libast.m4 b/libast.m4
index 521dec1..6a96332 100644
--- a/libast.m4
+++ b/libast.m4
@@ -253,13 +253,10 @@ AC_DEFUN([AST_STD_CHECKS], [
dnl# These must be run after AC_PROG_CC but before any other macros that
use
dnl# the C compiler
- AC_AIX
AC_ISC_POSIX
- AC_MINIX
dnl# At least make the attempt to support CygWin32
AC_CYGWIN
- AC_ARG_PROGRAM
AM_PROG_LIBTOOL
@@ -342,6 +339,36 @@ AC_DEFUN([AST_TYPE_CHECKS], [
])
dnl#
+dnl# LibAST Compiler Checks
+dnl#
+AC_DEFUN([AST_COMPILER_CHECKS], [
+ AC_MSG_CHECKING([for ({...}) compiler support])
+ AC_CACHE_VAL(ast_compiler_compound_statement_expr, [
+ AC_TRY_COMPILE(
+ changequote(<<, >>)dnl
+<<
+int main(void)
+{
+ int a = 1, b = 2, c = 3, d;
+
+ d = ({ b *= c; a += b - c; a + b + c; });
+ return 0;
+} >>
+ changequote([, ])
+ , ast_compiler_compound_statement_expr=0,
ast_compiler_compound_statement_expr=1, ast_compiler_compound_statement_expr=2)
+ ])
+ if test $ast_compiler_compound_statement_expr -eq 0; then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([LIBAST_SUPPORT_MACRO_CSE], [1], [Defined if compiler
supports compound statement expressions.])
+ elif test $ast_compiler_compound_statement_expr -eq 1; then
+ AC_MSG_RESULT([no])
+ else
+ AC_MSG_RESULT([unknown, assuming none])
+ fi
+])
+
+
+dnl#
dnl# LibAST argument macros
dnl# - arg 1 is the name of the env var to use
dnl#
@@ -462,7 +489,7 @@ exit(0);
])
if test $dps_cv_snprintf_bug -eq 0; then
AC_MSG_RESULT([no, snprintf is ok])
- elif test $dps_cv_snprint_bug -eq 1; then
+ elif test $dps_cv_snprintf_bug -eq 1; then
AC_MSG_RESULT([yes, snprintf is broken])
AC_DEFINE([HAVE_SNPRINTF_BUG], [1], [Defined if libc snprintf is
buggy.])
else
diff --git a/libast.spec b/libast.spec
index 13a0912..196be51 100644
--- a/libast.spec
+++ b/libast.spec
@@ -1,5 +1,5 @@
%define __os_install_post /usr/lib/rpm/brp-compress
-%if %{?optflags:1}0
+%if %{!?optflags:1}0
%define optflags ${RPM_OPT_FLAGS:--O0 -g3}
%endif
diff --git a/src/mbuff.c b/src/mbuff.c
index 1d83504..6d2bd1a 100644
--- a/src/mbuff.c
+++ b/src/mbuff.c
@@ -664,24 +664,33 @@ spif_mbuff_sprintf(spif_mbuff_t self, spif_charptr_t
format, ...)
if (self->buff != (spif_byteptr_t) NULL) {
spif_mbuff_done(self);
}
- if (*format == 0) {
+ if (!format) {
+ return FALSE;
+ } else if (*format == 0) {
return TRUE;
- } else if (*(format + 1) == 0) {
- return spif_mbuff_init_from_ptr(self, format, 2);
} else {
int c;
char buff[2];
+ va_start(ap, format);
c = vsnprintf(buff, sizeof(buff), format, ap);
+ va_end(ap);
if (c <= 0) {
- return TRUE;
+ return FALSE;
} else {
c++;
- self->len = self->size = c;
+ self->size = c;
self->buff = (spif_charptr_t) MALLOC(self->size);
+ va_start(ap, format);
c = vsnprintf(self->buff, self->size, format, ap);
+ va_end(ap);
+ if (c > -1 && c < self->size) {
+ self->len = c;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
}
- return ((c >= 0) ? (TRUE) : (FALSE));
}
ASSERT_NOTREACHED_RVAL(FALSE);
}
diff --git a/src/str.c b/src/str.c
index c3ac4c7..94f78c2 100644
--- a/src/str.c
+++ b/src/str.c
@@ -712,28 +712,36 @@ spif_str_sprintf(spif_str_t self, spif_charptr_t format,
...)
va_list ap;
ASSERT_RVAL(!SPIF_STR_ISNULL(self), FALSE);
- va_start(ap, format);
if (self->s != (spif_charptr_t) NULL) {
spif_str_done(self);
}
- if (*format == 0) {
+ if (!format) {
+ return FALSE;
+ } else if (*format == 0) {
return TRUE;
- } else if (*(format + 1) == 0) {
- return spif_str_init_from_ptr(self, format);
} else {
int c;
char buff[2];
+ va_start(ap, format);
c = vsnprintf(buff, sizeof(buff), format, ap);
+ va_end(ap);
if (c <= 0) {
- return TRUE;
+ return FALSE;
} else {
- self->len = c;
self->size = c + 1;
self->s = (spif_charptr_t) MALLOC(self->size);
- c = vsnprintf(self->s, c + 1, format, ap);
+ va_start(ap, format);
+ c = vsnprintf(self->s, self->size, format, ap);
+ va_end(ap);
+ if (c > -1 && c < self->size) {
+ self->len = c;
+ return TRUE;
+ } else {
+ self->s[0] = 0;
+ return FALSE;
+ }
}
- return ((c >= 0) ? (TRUE) : (FALSE));
}
ASSERT_NOTREACHED_RVAL(FALSE);
}
diff --git a/src/ustr.c b/src/ustr.c
index 4fb8e91..164677a 100644
--- a/src/ustr.c
+++ b/src/ustr.c
@@ -712,28 +712,36 @@ spif_ustr_sprintf(spif_ustr_t self, spif_charptr_t
format, ...)
va_list ap;
ASSERT_RVAL(!SPIF_USTR_ISNULL(self), FALSE);
- va_start(ap, format);
if (self->s != (spif_charptr_t) NULL) {
spif_ustr_done(self);
}
- if (*format == 0) {
+ if (!format) {
+ return FALSE;
+ } else if (*format == 0) {
return TRUE;
- } else if (*(format + 1) == 0) {
- return spif_ustr_init_from_ptr(self, format);
} else {
int c;
char buff[2];
+ va_start(ap, format);
c = vsnprintf(buff, sizeof(buff), format, ap);
+ va_end(ap);
if (c <= 0) {
- return TRUE;
+ return FALSE;
} else {
- self->len = c;
self->size = c + 1;
self->s = (spif_charptr_t) MALLOC(self->size);
- c = vsnprintf(self->s, c + 1, format, ap);
+ va_start(ap, format);
+ c = vsnprintf(self->s, self->size, format, ap);
+ va_end(ap);
+ if (c > -1 && c < self->size) {
+ self->len = c;
+ return TRUE;
+ } else {
+ self->s[0] = 0;
+ return FALSE;
+ }
}
- return ((c >= 0) ? (TRUE) : (FALSE));
}
ASSERT_NOTREACHED_RVAL(FALSE);
}
--
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev