From 13ba081ac82639c1a430452d69006496e21805d4 Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Sun, 5 Jul 2015 21:52:41 +0200 Subject: [PATCH] primitive_format_float, return empty string on bad locale instead of C++ exception --- vm/math.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vm/math.cpp b/vm/math.cpp index c2b5714013..37d3d0df7e 100644 --- a/vm/math.cpp +++ b/vm/math.cpp @@ -1,6 +1,7 @@ #include "master.hpp" #include #include +#include namespace factor { @@ -220,7 +221,14 @@ void factor_vm::primitive_format_float() { char* fill = alien_offset(ctx->pop()); double value = untag_float_check(ctx->peek()); std::ostringstream localized_stream; - localized_stream.imbue(std::locale(locale)); + try { + localized_stream.imbue(std::locale(locale)); + } catch (const runtime_error& error) { + byte_array* array = allot_byte_array(1); + array->data()[0] = '\0'; + ctx->replace(tag(array)); + return; + } switch (format[0]) { case 'f': localized_stream << std::fixed; break; case 'e': localized_stream << std::scientific; break;