[Bf-blender-cvs] [bb2eca07a68] soc-2020-io-performance: Catch out of range exceptions for stoi/stof.

Ankit Meel noreply at git.blender.org
Mon Aug 10 23:53:08 CEST 2020


Commit: bb2eca07a68a6d5e739cdf36f3eb9da2864f2690
Author: Ankit Meel
Date:   Tue Aug 11 03:20:59 2020 +0530
Branches: soc-2020-io-performance
https://developer.blender.org/rBbb2eca07a68a6d5e739cdf36f3eb9da2864f2690

Catch out of range exceptions for stoi/stof.

===================================================================

M	source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc

===================================================================

diff --git a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
index 1f4ceb5ce83..920341644df 100644
--- a/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
+++ b/source/blender/io/wavefront_obj/intern/wavefront_obj_im_file_reader.cc
@@ -123,6 +123,11 @@ void copy_string_to_float(string_view src, const float fallback_value, float &r_
     std::cerr << "Bad conversion to float:'" << inv_arg.what() << "':'" << src << "'" << std::endl;
     r_dst = fallback_value;
   }
+  catch (const std::out_of_range &out_of_range) {
+    std::cerr << "Out of range for float:'" << out_of_range.what() << ":'" << src << "'"
+              << std::endl;
+    r_dst = fallback_value;
+  }
 }
 
 /**
@@ -157,6 +162,10 @@ BLI_INLINE void copy_string_to_int(string_view src, const int fallback_value, in
     std::cerr << "Bad conversion to int:'" << inv_arg.what() << "':'" << src << "'" << std::endl;
     r_dst = fallback_value;
   }
+  catch (const std::out_of_range &out_of_range) {
+    std::cerr << "Out of range for int:'" << out_of_range.what() << ":'" << src << "'"
+              << std::endl;
+  }
 }
 
 /**
@@ -314,16 +323,9 @@ void OBJParser::parse_and_store(Vector<std::unique_ptr<Geometry>> &all_geometrie
       /* Some implementations use "0" and "null" too, in addition to "off". */
       if (rest_line != "0" && rest_line.find("off") == string::npos &&
           rest_line.find("null") == string::npos) {
-        /* TODO ankitm make a string to bool function if need arises. */
-        try {
-          std::stoi(string(rest_line));
-          shaded_smooth = true;
-        }
-        catch (const std::invalid_argument &inv_arg) {
-          std::cerr << "Bad argument for smooth shading:'" << inv_arg.what() << "':'" << rest_line
-                    << "'" << std::endl;
-          shaded_smooth = false;
-        }
+        int smooth = 0;
+        copy_string_to_int(rest_line, 0, smooth);
+        shaded_smooth = smooth != 0;
       }
       else {
         /* The OBJ file explicitly set shading to off. */



More information about the Bf-blender-cvs mailing list