Hello,
I noticed that only %f is supported in string_builder_vsprintf(). I
would like to use something else in JSON2, so it would be nice if
someone could review this and maybe commit.
arne
diff --git a/src/stralloc.c b/src/stralloc.c
index eb60b8b..e75d45b 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -2945,13 +2945,17 @@ PMOD_EXPORT void string_builder_vsprintf(struct string_builder *s,
flags, min_width, precision);
break;
- /* FIMXE: TODO: Doubles (ie 'a', 'e', 'E', 'g', 'G'). */
-
/* %f used in modules/Image/colors.c. */
+ case 'a':
+ case 'g':
+ case 'G':
+ case 'e':
+ case 'E':
case 'f':
{
double val = va_arg(args, double);
size_t bytes;
+ char nfmt[] = { '%', *(fmt-1), 0 };
if (PIKE_ISNAN(val)) {
/* NaN */
@@ -2974,9 +2978,9 @@ PMOD_EXPORT void string_builder_vsprintf(struct string_builder *s,
break;
}
/* FIXME: Field lengths and precision. */
- if ((bytes = SNPRINTF(NULL, 0, "%f", val))) {
+ if ((bytes = SNPRINTF(NULL, 0, nfmt, val))) {
p_wchar0 *p = string_builder_allocate(s, bytes, 0);
- size_t check = SNPRINTF((char*)p, bytes+1, "%f", val);
+ size_t check = SNPRINTF((char*)p, bytes+1, nfmt, val);
if (check != bytes) {
Pike_fatal("string_builder_vsprintf(): snprintf(%f) is not "
"trustworthy: %"PRINTSIZET"u != %"PRINTSIZET"u\n",