Oops - mis-read the input limit, sorry.
I added some locale debug, and it still crashes.
But it crashes inside the shutdown code in libc, not the actual program.
Code:
$ gcc -g -Wall foo.c
$ gdb -q ./a.out
Reading symbols from ./a.out...done.
(gdb) list
1 #include <stdlib.h>
2 #include <wchar.h>
3 #include <locale.h>
4
5 int main(void) {
6 wchar_t buffer[10+1] = { 0 };
7 char *lc;
8
9 lc = setlocale(LC_ALL,NULL);
10 wprintf(L"Old locale=%s\n", lc ? lc : "setlocale failed");
(gdb)
11 lc = setlocale(LC_ALL, "");
12 wprintf(L"New locale=%s\n", lc ? lc : "setlocale failed");
13
14 wprintf(L"Input please: ");
15 wscanf(L"%10ls", buffer);
16 wprintf(L"--> %zu %ls\n", wcslen(buffer), buffer);
17
18 return EXIT_SUCCESS;
19 }
(gdb) b 18
Breakpoint 1 at 0x400785: file foo.c, line 18.
(gdb) run
Starting program: ./a.out
Old locale=C
New locale=en_GB.UTF-8
Input please: llllllllllllllllll
--> 10 llllllllll
Breakpoint 1, main () at foo.c:18
18 return EXIT_SUCCESS;
(gdb) p sizeof(buffer)
$1 = 44
(gdb) x/44xb buffer
0x7fffffffddd0: 0x6c 0x00 0x00 0x00 0x6c 0x00 0x00 0x00
0x7fffffffddd8: 0x6c 0x00 0x00 0x00 0x6c 0x00 0x00 0x00
0x7fffffffdde0: 0x6c 0x00 0x00 0x00 0x6c 0x00 0x00 0x00
0x7fffffffdde8: 0x6c 0x00 0x00 0x00 0x6c 0x00 0x00 0x00
0x7fffffffddf0: 0x6c 0x00 0x00 0x00 0x6c 0x00 0x00 0x00
0x7fffffffddf8: 0x00 0x00 0x00 0x00
(gdb) c
Continuing.
Program received signal SIGSEGV, Segmentation fault.
__GI__IO_wfile_sync (fp=0x0) at wfileops.c:534
534 wfileops.c: No such file or directory.
(gdb) bt
#0 __GI__IO_wfile_sync (fp=0x0) at wfileops.c:534
#1 0x00007ffff7a89947 in _IO_default_setbuf (fp=fp@entry=0x7ffff7dd18e0 <_IO_2_1_stdin_>, p=0x0, len=0)
at genops.c:523
#2 0x00007ffff7a86439 in _IO_new_file_setbuf (fp=0x7ffff7dd18e0 <_IO_2_1_stdin_>, p=<optimised out>,
len=<optimised out>) at fileops.c:451
#3 0x00007ffff7a8a39f in _IO_unbuffer_all () at genops.c:915
#4 _IO_cleanup () at genops.c:960
#5 0x00007ffff7a47f9b in __run_exit_handlers (status=0, listp=<optimised out>,
run_list_atexit=run_list_atexit@entry=true) at exit.c:95
#6 0x00007ffff7a48045 in __GI_exit (status=<optimised out>) at exit.c:104
#7 0x00007ffff7a2e837 in __libc_start_main (main=0x400696 <main>, argc=1, argv=0x7fffffffdef8,
init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fffffffdee8)
at ../csu/libc-start.c:325
#8 0x00000000004005c9 in _start ()
There is no sign of data overrun in buffer, as shown by the x command. Indeed had there been, it would be unlikely that main would have returned successfully.
This might be a library bug.
Bugs : glibc package : Ubuntu doesn't show anything relevant for locale, though there are several locale issues.