Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0-staging] Fix a bug in PAL version of _vsnprint_f #103003

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/safecrt/vsprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ DLLEXPORT int __cdecl _vsnprintf_s (
retvalue = vsnprintf(string, sizeInBytes, format, ap);
string[sizeInBytes - 1] = '\0';
/* we allow truncation if count == _TRUNCATE */
if (retvalue > (int)sizeInBytes && count == _TRUNCATE)
if (retvalue >= (int)sizeInBytes && count == _TRUNCATE)
{
if (errno == ERANGE)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ PALTEST(c_runtime__vsnprintf_s_test1_paltest_vsnprintf_test1, "c_runtime/_vsnpri
Fail("ERROR: expected %s (up to %d chars), got %s\n", checkstr, 8, buf);
}

char buf8[8] = {0};

ret = Testvsnprintf(buf8, 8, "abcdefgh");
if (ret >= 0)
{
Fail("ERROR: expected negative return value, got %d", ret);
}
if (memcmp(buf8, "abcdefg\0", 8) != 0)
{
Fail("ERROR: Expected 7 chars + null terminator");
}

PAL_Terminate();
return PASS;
}
Loading