- input = xrealloc (input, length + 3);
- if (length == 0 || input[length - 1] != '\n')
- input[length++] = '\n';
- input[length++] = '\0';
+
+ if (!check_truncations)
+ {
+ input = xrealloc (input, length + 3);
+ if (length == 0 || input[length - 1] != '\n')
+ input[length++] = '\n';
+ input[length++] = '\0';
+
+ check_segmentation (input, length, true);
+ }
+ else
+ {
+ size_t test_len;
+
+ for (test_len = 0; test_len <= length; test_len++)
+ {
+ char *copy = xmemdup0 (input, test_len);
+ check_segmentation (copy, test_len + 1, false);
+ free (copy);
+ }
+ }
+ free (input);
+
+ return 0;
+}
+
+static void
+check_segmentation (const char *input, size_t length, bool print_segments)
+{
+ size_t offset, line_number, line_offset;
+ struct segmenter s;
+ int prev_type;