summaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
authorMichael Jennings <mej@lbl.gov>2013-03-05 12:58:01 -0800
committerMichael Jennings <mej@lbl.gov>2013-03-05 12:58:01 -0800
commit9d0be7b7d259415771e22565fe29bafe52df3606 (patch)
tree0c8a29bffa425b0fbd8264bc91074740f8a45f1a /src/str.c
parent0527261a853b728c76b22cd11f6cbaf80d2a486f (diff)
downloadlibast-9d0be7b7d259415771e22565fe29bafe52df3606.tar.gz
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.
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c24
1 files changed, 16 insertions, 8 deletions
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);
}