Commit f49a8e5d authored by Mark Andrews's avatar Mark Andrews

Merge branch '274-print-c-9-12-and-earlier-v9_11' into 'v9_11'

Resolve "print.c 9.12 and earlier"

See merge request !298
parents 28f17e82 7bbc0668
Pipeline #1752 passed with stages
in 6 minutes and 9 seconds
4949. [bug] lib/isc/print.c failed to handle floating point
output correctly. [GL #261]
4939. [test] Add basic unit tests for update_sigs(). [GL #135]
4935. [func] Add support for LibreSSL >= 2.7.0 (some OpenSSL 1.1.0
......
......@@ -3773,12 +3773,14 @@ AC_CHECK_FUNC(vsnprintf, [],
AC_MSG_CHECKING(printf for %z support)
AC_TRY_RUN([
#include <stdio.h>
int
main() {
size_t j = 0;
char buf[100];
buf[0] = 0;
sprintf(buf, "%zu", j);
exit(strcmp(buf, "0") != 0);
return ((buf[0] == '0' && buf[1] == '\0') ? 0 : 1);
}
],
[AC_MSG_RESULT(yes)],
......
......@@ -685,7 +685,7 @@ isc__print_printf(void (*emit)(char, void *), void *arg,
pad--;
}
cp = buf;
while (*cp != ' ')
while (*cp != '\0')
emit(*cp++, arg);
while (pad > 0) {
emit(' ', arg);
......
......@@ -50,6 +50,7 @@ ATF_TC_BODY(snprintf, tc) {
isc_uint64_t ll = 8589934592ULL;
isc_uint64_t nn = 20000000000000ULL;
isc_uint64_t zz = 10000000000000000000ULL;
float pi = 3.141;
int n;
size_t size;
......@@ -118,6 +119,25 @@ ATF_TC_BODY(snprintf, tc) {
n = isc_print_snprintf(buf, sizeof(buf), "0x%"ISC_PRINT_QUADFORMAT"x", zz);
ATF_CHECK_EQ(n, 18);
ATF_CHECK_STREQ(buf, "0xf5f5f5f5f5f5f5f5");
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");
/* Similar to the above, but with leading spaces */
n = isc_print_snprintf(buf, sizeof(buf), "% 8.2f1592", pi);
ATF_CHECK_EQ(n, 12);
ATF_CHECK_STREQ(buf, " 3.141592");
/* Similar to the above, but with trail spaces after the 4 */
n = isc_print_snprintf(buf, sizeof(buf), "%-8.2f1592", pi);
ATF_CHECK_EQ(n, 12);
ATF_CHECK_STREQ(buf, "3.14 1592");
}
ATF_TC(fprintf);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment