commit - 7a54ad3ae5d25aa5349668c8d3d3fa048a8f0733
commit + 6f26cb2ecbe03d692e63a4f263febfb5a74e4377
blob - 92887ff151b6faa423752b1fa9baa3c123f19726
blob + 51cb9c7966c778bceaaaf06691252cd4887e5e63
--- include/diff/diff_output.h
+++ include/diff/diff_output.h
const struct diff_result *result,
unsigned int context_lines);
int diff_output_info(FILE *dest, const struct diff_input_info *info);
-void diff_output_lines(FILE *dest, const char *prefix,
+int diff_output_lines(FILE *dest, const char *prefix,
struct diff_atom *start_atom, unsigned int count);
blob - e93c1e9cc1701fc9a4f1d457d33924914bb20adf
blob + e9dd89fa1226d66603de9f1e80fd72bca21fefcb
--- lib/diff_output.c
+++ lib/diff_output.c
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <diff/diff_main.h>
#include <diff/diff_output.h>
-static char
-get_atom_byte(struct diff_atom *atom, off_t off)
+static int
+get_atom_byte(int *ch, struct diff_atom *atom, off_t off)
{
- int ch;
off_t cur;
- if (atom->at != NULL)
- return atom->at[off];
+ if (atom->at != NULL) {
+ *ch = atom->at[off];
+ return 0;
+ }
cur = ftello(atom->d->root->f);
if (cur == -1)
- abort(); /* XXX cannot return error */
+ return errno;
if (cur != atom->pos + off &&
fseeko(atom->d->root->f, atom->pos + off, SEEK_SET) == -1)
- abort(); /* XXX cannot return error */
+ return errno;
- ch = fgetc(atom->d->root->f);
- if (ch == EOF)
- abort(); /* XXX cannot return error */
+ *ch = fgetc(atom->d->root->f);
+ if (*ch == EOF && ferror(atom->d->root->f))
+ return errno;
- return ch;
+ return 0;
}
-void
+int
diff_output_lines(FILE *dest, const char *prefix, struct diff_atom *start_atom,
unsigned int count)
{
struct diff_atom *atom;
+ int rc;
foreach_diff_atom(atom, start_atom, count) {
fprintf(dest, "%s", prefix);
- int i;
+ int i, ch;
unsigned int len = atom->len;
if (len) {
- char ch;
- ch = get_atom_byte(atom, len - 1);
+ rc = get_atom_byte(&ch, atom, len - 1);
+ if (rc)
+ return rc;
if (ch == '\n')
len--;
if (len) {
- ch = get_atom_byte(atom, len - 1);
+ rc = get_atom_byte(&ch, atom, len - 1);
+ if (rc)
+ return rc;
if (ch == '\r')
len--;
}
}
for (i = 0; i < len; i++) {
- char c = get_atom_byte(atom, i);
- if ((c < 0x20 || c >= 0x7f) && c != '\t')
- fprintf(dest, "\\x%02x", (unsigned char)c);
+ rc = get_atom_byte(&ch, atom, i);
+ if (rc)
+ return rc;
+ if ((ch < 0x20 || ch >= 0x7f) && ch != '\t')
+ fprintf(dest, "\\x%02x", (unsigned char)ch);
else
- fprintf(dest, "%c", c);
+ fprintf(dest, "%c", ch);
}
fprintf(dest, "\n");
}
+
+ return 0;
}