]> gitweb.factorcode.org Git - factor.git/commitdiff
primitive_format_float, return empty string on bad locale instead of C++ exception
authorJon Harper <jon.harper87@gmail.com>
Sun, 5 Jul 2015 19:52:41 +0000 (21:52 +0200)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 8 Mar 2016 15:55:25 +0000 (07:55 -0800)
vm/math.cpp

index c2b57140136f7d3068daa375be17d80f840c72c9..37d3d0df7ed089fa5b0624b16d9bf7a6a2567fdb 100644 (file)
@@ -1,6 +1,7 @@
 #include "master.hpp"
 #include <sstream>
 #include <iomanip>
+#include <stdexcept>
 
 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<char>()[0] = '\0';
+    ctx->replace(tag<byte_array>(array));
+    return;
+  }
   switch (format[0]) {
     case 'f': localized_stream << std::fixed; break;
     case 'e': localized_stream << std::scientific; break;