This is a bug in the Linux glibc swprintf implementation which in some cases does not write null terminator into the last position of output buffer.
https://sourceware.org/bugzilla/show_bug.cgi?id=27857
This bug was recently fixed in the new glibc version 2.37. So after upgrading system library to new version, the provided example start working correctly.
As a workaround for older glibc versions (pre-2.37), it is possible to explicitly add null terminator. For example following code adds null terminator conditionally only when compiling for glibc and only when compiling for old version affected by that bug:
#include <iostream>
#include <string>
#include <cwchar>
int main()
{
wchar_t wide[5];
std::swprintf(wide, sizeof wide/sizeof *wide, L"%ls", L"111111111");
#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 37))
wide[(sizeof wide/sizeof *wide)-1] = L'\0';
#endif
std::wcout << wide;
}