`mousepad_history_autosave_get_location` enters an infinite loop on most actions involving multiple documents/windows
I believe there's some UB in the mousepad_history_autosave_get_location
function that the optimizer is exploiting, since the loop it compiles to is very weird:
Dump of assembler code for function mousepad_history_autosave_get_location:
0x00007fbd79065130 <+0>: push r13
0x00007fbd79065132 <+2>: mov eax,DWORD PTR [rip+0x40348] # 0x7fbd790a5480 <autosave_id.0>
0x00007fbd79065138 <+8>: mov esi,0x1
0x00007fbd7906513d <+13>: push r12
0x00007fbd7906513f <+15>: mov edi,DWORD PTR [rip+0x40353] # 0x7fbd790a5498 <autosave_ids>
0x00007fbd79065145 <+21>: push rbp
0x00007fbd79065146 <+22>: nop WORD PTR cs:[rax+rax*1+0x0]
=> 0x00007fbd79065150 <+32>: mov ecx,eax
0x00007fbd79065152 <+34>: mov edx,esi
0x00007fbd79065154 <+36>: add eax,0x1
0x00007fbd79065157 <+39>: shl edx,cl
0x00007fbd79065159 <+41>: test edx,edi
0x00007fbd7906515b <+43>: jne 0x7fbd79065150 <mousepad_history_autosave_get_location+32>
0x00007fbd7906515d <+45>: mov esi,ecx
0x00007fbd7906515f <+47>: lea rdi,[rip+0x18711] # 0x7fbd7907d877
0x00007fbd79065166 <+54>: mov DWORD PTR [rip+0x40314],eax # 0x7fbd790a5480 <autosave_id.0>
0x00007fbd7906516c <+60>: xor eax,eax
0x00007fbd7906516e <+62>: call 0x7fbd790548b0 <g_strdup_printf@plt>
...
Mousepad enters this loop when trying to recover a large session and trying to open new windows. I'm unsure what exact state is necessary for reproduction since I can only find autosave-* files in ~/.local/share/Mousepad, but not the rest of the saved session state or the config.
Version details
Mousepad 0.5.9 installed from NixOS unstable channel version 22.11pre392657.e4d49de45a3
Let me know if more details are needed, I could try to compile with sanitizers but I'd prefer not to lose sanity wrangling build systems during holidays.