diff --git a/locale.c b/locale.c index e71748b9d88d..54a1fb464238 100644 --- a/locale.c +++ b/locale.c @@ -2811,6 +2811,20 @@ S_save_to_buffer(const char * string, const char **buf, Size_t *buf_size) "Copying '%s' to %p\n", string, *buf)); } +# ifdef DEBUGGING + + /* Catch glitches. Usually this is because LC_CTYPE needs to be the same + * locale as whatever is being worked on */ + if (UNLIKELY(instr(string, REPLACEMENT_CHARACTER_UTF8))) { + dTHX_DEBUGGING; + + locale_panic_(Perl_form(aTHX_ + "Unexpected REPLACEMENT_CHARACTER in '%s'\n%s", + string, get_LC_ALL_display())); + } + +# endif + Copy(string, *buf, string_size, char); return *buf; }