Valgrind:
```
==80929== Invalid read of size 2
==80929== at 0x4842B30: memmove (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==80929== by 0x43618E: char* std::__copy_move<false, true, std::random_access_iterator_tag>::__copy_m<char>(char const*, char const*, char*) (stl_algobase.h:386)
==80929== by 0x435ABC: char* std::__copy_move_a<false, char const*, char*>(char const*, char const*, char*) (stl_algobase.h:404)
==80929== by 0x436131: char* std::__copy_move_a2<false, char const*, char*>(char const*, char const*, char*) (stl_algobase.h:440)
==80929== by 0x4359BF: char* std::copy<char const*, char*>(char const*, char const*, char*) (stl_algobase.h:474)
==80929== by 0x59F28C: Array<char, DefaultAllocator<char> >::Array<char const*>(char const*, char const*) (array.h:86)
==80929== by 0x59A2A0: Preferences_Save_Safe(PreferenceDictionary&, char const*) (preferences.cpp:207)
==80929== by 0x59C7A2: Preferences_Save() (preferences.cpp:919)
==80929== by 0x524500: Radiant_Shutdown() (mainframe.cpp:798)
==80929== by 0x5223FB: main (main.cpp:654)
==80929== Address 0xba88510 is 0 bytes after a block of size 64 alloc'd
==80929== at 0x483B723: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==80929== by 0x483E017: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==80929== by 0x5272F3F: g_realloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6)
==80929== by 0x5290003: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6)
==80929== by 0x5290066: g_string_sized_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6)
==80929== by 0x52905BA: g_string_new (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6)
==80929== by 0x59B65A: PrefsDlg::Init() (preferences.cpp:551)
==80929== by 0x5222A1: main (main.cpp:595)
```
}
bool Preferences_Save_Safe( PreferenceDictionary& preferences, const char* filename ){
- Array<char> tmpName( filename, filename + strlen( filename ) + 1 + 3 );
- *( tmpName.end() - 4 ) = 'T';
- *( tmpName.end() - 3 ) = 'M';
- *( tmpName.end() - 2 ) = 'P';
- *( tmpName.end() - 1 ) = '\0';
+ std::string tmpName( filename );
+ tmpName += "TMP";
- return Preferences_Save( preferences, tmpName.data() )
+ return Preferences_Save( preferences, tmpName.c_str() )
&& ( !file_exists( filename ) || file_remove( filename ) )
&& file_move( tmpName.data(), filename );
}