Skip to content

[libc++] [windows] Crash with Norwegian regional settings #160478

@lb90

Description

@lb90

This can be reproduced on any system with:

#include <clocale>
#include <cstdint>
#include <iostream>

int
main (void)
{
  std::setlocale (LC_ALL, "norwegian-bokmal.UTF-8");
  uint16_t x = 0;
  std::cout << x << "\n";

  return 0;
}

Here's a stack trace:

libc++abi: terminating due to uncaught exception of type std::bad_alloc: std::bad_alloc
gdb: unknown target exception 0xc0000409 at 0x7fff80d14ace

Thread 1 received signal ?, Unknown signal.
0x00007fff80d14ace in ucrtbase!abort () from C:\WINDOWS\System32\ucrtbase.dll
(gdb) bt
#0  0x00007fff80d14ace in ucrtbase!abort () from C:\WINDOWS\System32\ucrtbase.dll
#1  0x00007ffeecaf7686 in __abort_message (format=0x7ffeecb99509 <typeinfo name for std::bad_alloc+65> "terminating due to %s exception of type %s: %s")
    at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxxabi/src\abort_message.cpp:66
#2  0x00007ffeecad3f79 in demangling_terminate_handler () at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxxabi/src\cxa_default_handlers.cpp:72
#3  0x00007ffeecaf65d6 in std::__terminate (func=0x7) at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxxabi/src\cxa_handlers.cpp:59
#4  0x00007ffeecaf6570 in std::terminate () at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxxabi/src\cxa_handlers.cpp:88
#5  0x00007ffeecaf625e in __clang_call_terminate () from D:\msys64\clang64\bin\libc++.dll
#6  0x00007ffeecb7c21a in std::__1::__locale::__locale_guard::~__locale_guard[abi:ne210101]() (this=0x14f8e8)
    at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/include/__locale_dir/support/windows.h:324
#7  std::__1::__locale::__wcrtomb (s=s@entry=0x14f96b "", wc=0 L'\000', ps=ps@entry=0x7ffeecc12838, loc=...)
    at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/src/support/win32\locale_win32.cpp:97
#8  0x00007ffeecb44e0c in std::__1::codecvt<wchar_t, char, _Mbstatet>::do_unshift (this=0x7ffeecc13548, st=..., to=0x14f9f0 "\002", to_end=0x14f9f8 "\242&\333~`|\303x\2407\301\354\376\177", 
    to_nxt=@0x14f9e8: 0x14f9f0 "\002") at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/src\locale.cpp:1395
#9  0x00007ffeecb3d919 in std::__1::codecvt<wchar_t, char, _Mbstatet>::unshift[abi:ne210101](_Mbstatet&, char*, char*, char*&) const (this=0x7, __st=..., __to=0x14f9f0 "\002", 
    __to_end=0x14f9f8 "\242&\333~`|\303x\2407\301\354\376\177", __to_nxt=@0x14f9e8: 0x14f9f0 "\002") at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/include/__locale:842    
#10 std::__1::__stdoutbuf<wchar_t>::sync (this=0x7ffeecc127d8) at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/src/std_stream.h:364
#11 0x00007ffeecb31df9 in std::__1::basic_streambuf<wchar_t, std::__1::char_traits<wchar_t> >::pubsync (this=0x7)
    at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/include/streambuf:176
#12 std::__1::basic_ostream<wchar_t, std::__1::char_traits<wchar_t> >::flush (this=warning: (Internal error: pc 0x7ffeecc12738 in read in CU, but not in symtab.)
warning: (Error: pc 0x7ffeecc12738 in address map, but not in symtab.)
0x7ffeecc12738)
    at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/include/__ostream/basic_ostream.h:502
#13 0x00007ffeecb3c1a8 in std::__1::DoIOSInit::~DoIOSInit (this=<optimized out>) at C:/Users/lucab/MINGW-packages/mingw-w64-libc++/src/llvm-project-21.1.1.src/libcxx/src\iostream.cpp:127

This issue is a follow-up from Exiv2/exiv2#3225

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions