Give better errors on malformed subrip times.
authorCarl Hetherington <cth@carlh.net>
Fri, 15 Mar 2019 16:27:50 +0000 (16:27 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 15 Mar 2019 16:27:50 +0000 (16:27 +0000)
src/subrip_reader.cc

index 16ba0a5beb6431083f1043e3dfcdb266072593aa..cf0b86f9847e75d0f4f465d218fc680f4a18f14e 100644 (file)
@@ -158,12 +158,33 @@ SubripReader::convert_time (string t)
                throw SubripError (t, "time in the format h:m:s,ms", _context);
        }
 
-       return Time::from_hms (
-               lexical_cast<int> (a[0]),
-               lexical_cast<int> (a[1]),
-               lexical_cast<int> (b[0]),
-               lexical_cast<int> (b[1])
-               );
+       int h, m, s, ms;
+
+       try {
+               h = lexical_cast<int>(a[0]);
+       } catch (boost::bad_lexical_cast &) {
+               throw SubripError (t, "integer hour value", _context);
+       }
+
+       try {
+               m = lexical_cast<int>(a[1]);
+       } catch (boost::bad_lexical_cast &) {
+               throw SubripError (t, "integer minute value", _context);
+       }
+
+       try {
+               s = lexical_cast<int>(b[0]);
+       } catch (boost::bad_lexical_cast &) {
+               throw SubripError (t, "integer second value", _context);
+       }
+
+       try {
+               ms = lexical_cast<int>(b[1]);
+       } catch (boost::bad_lexical_cast &) {
+               throw SubripError (t, "integer millisecond value", _context);
+       }
+
+       return Time::from_hms (h, m, s, ms);
 }
 
 void