Fix crash with empty SSA subtitle.
[libsub.git] / src / ssa_reader.cc
index 471931fe2056141e75a23c1bd0c86112c05c62d9..b899da6151b7eeab10fb1a10b689853679edfa7f 100644 (file)
@@ -212,9 +212,11 @@ SSAReader::parse_line (RawSubtitle base, string line, int play_res_x, int play_r
 
        /* Count the number of line breaks */
        int line_breaks = 0;
-       for (size_t i = 0; i < line.length() - 1; ++i) {
-               if (line[i] == '\\' && (line[i+1] == 'n' || line[i+1] == 'N')) {
-                       ++line_breaks;
+       if (line.length() > 1) {
+               for (size_t i = 0; i < line.length() - 1; ++i) {
+                       if (line[i] == '\\' && (line[i+1] == 'n' || line[i+1] == 'N')) {
+                               ++line_breaks;
+                       }
                }
        }