isc__print_printf omits characters after %f
Summary
Another submission from Infoblox, who would like us to know that isc__print_printf omits characters after %f
Steps to reproduce
Jinmei says:
Try this test code and see the second ATF_CHECK_STREQ() fail. I believe that should be enough to explain the problem (the first chunk of ATF_CHECK_xx is actually irrelevant to the bug; I added it just to first confirm a more basic case) .
float pi = 3.141;
n = isc_print_snprintf(buf, sizeof(buf), "%.2f", pi);
ATF_CHECK_EQ(n, 4);
ATF_CHECK_STREQ(buf, "3.14");
/* Similar to the above, but additional characters follows */
n = isc_print_snprintf(buf, sizeof(buf), "%.2f1592", pi);
ATF_CHECK_EQ(n, 8);
ATF_CHECK_STREQ(buf, "3.141592");
Possible fixes
The following patch would fix this issue. The same problem seems to exist for other versions than 9.11.3-S1, too.
diff --git a/lib/isc/print.c b/lib/isc/print.c
index 55843c4..5588e13 100644
--- a/lib/isc/print.c
+++ b/lib/isc/print.c
@@ -685,7 +685,7 @@ isc__print_printf(void (*emit)(char, void *), void *arg,
pad--;
}
cp = buf;
- while (*cp != ' ')
+ while (*cp != '\0' && *cp != ' ')
emit(*cp++, arg);
while (pad > 0) {
emit(' ', arg);