strfmon_test: Reserve space for the null terminator

Otherwise strfmon(3) could overflow the buffer.

Here is mostly done for correctness and illustrative purposes, as there
is no chance it could actually happen.

Reviewed by:	kib
PR:	267410
Github PR:	#620
MFC after:	1 week
This commit is contained in:
Jose Luis Duran 2022-10-27 07:01:24 -03:00 committed by Konstantin Belousov
parent d96088b3ab
commit edcee003e5

View File

@ -55,7 +55,7 @@ ATF_TC_BODY(strfmon_locale_thousands, tc)
atf_tc_skip("multi-byte thousands-separator not found");
n = 1234.56;
strfmon(actual, sizeof(actual), "%i", n);
strfmon(actual, sizeof(actual) - 1, "%i", n);
strcpy(expected, "1");
strlcat(expected, ts, sizeof(expected));
@ -95,7 +95,7 @@ ATF_TC_BODY(strfmon_examples, tc)
for (i = 0; i < nitems(tests); ++i) {
snprintf(format, sizeof(format), "[%s] [%s] [%s]",
tests[i].format, tests[i].format, tests[i].format);
strfmon(actual, sizeof(actual), format,
strfmon(actual, sizeof(actual) - 1, format,
123.45, -123.45, 3456.781);
ATF_CHECK_STREQ_MSG(tests[i].expected, actual,
"[%s]", tests[i].format);
@ -135,7 +135,7 @@ ATF_TC_BODY(strfmon_cs_precedes_0, tc)
for (j = 0; j < 5; ++j) {
lc->n_sign_posn = j;
strfmon(buf, sizeof(buf), "[%n] ", -123.0);
strfmon(buf, sizeof(buf) - 1, "[%n] ", -123.0);
strlcat(actual, buf, sizeof(actual));
}
@ -178,7 +178,7 @@ ATF_TC_BODY(strfmon_cs_precedes_1, tc)
for (j = 0; j < 5; ++j) {
lc->n_sign_posn = j;
strfmon(buf, sizeof(buf), "[%n] ", -123.0);
strfmon(buf, sizeof(buf) - 1, "[%n] ", -123.0);
strlcat(actual, buf, sizeof(actual));
}
@ -206,7 +206,7 @@ ATF_TC_BODY(strfmon_international_currency_code, tc)
if (setlocale(LC_MONETARY, tests[i].locale) == NULL)
atf_tc_skip("unable to setlocale()");
strfmon(actual, sizeof(actual), "[%i]", 123.45);
strfmon(actual, sizeof(actual) - 1, "[%i]", 123.45);
ATF_CHECK_STREQ(tests[i].expected, actual);
}
}