Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ AC_CHECK_PROGS(DEFAULT_EDITOR, sensible-editor editor vim vi, vi)
CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
if test x"$GCC" = xyes; then
CFLAGS="$CFLAGS -Wall"
dnl Enable _FORTIFY_SOURCE for additional security and warnings
CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
fi

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(sys/types.h unistd.h error.h)

Expand Down
12 changes: 8 additions & 4 deletions src/interdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,15 +1572,19 @@ flipdiff (FILE *p1, FILE *p2, FILE *flip1, FILE *flip2)
/* Read headers. */
header1[0] = header1[1] = NULL;
linelen = 0;
getline (&header1[0], &linelen, p1);
if (getline (&header1[0], &linelen, p1) == -1)
error (EXIT_FAILURE, errno, "Failed to read patch header from first file");
linelen = 0;
getline (&header1[1], &linelen, p1);
if (getline (&header1[1], &linelen, p1) == -1)
error (EXIT_FAILURE, errno, "Failed to read patch header from first file");

header2[0] = header2[1] = NULL;
linelen = 0;
getline (&header2[0], &linelen, p2);
if (getline (&header2[0], &linelen, p2) == -1)
error (EXIT_FAILURE, errno, "Failed to read patch header from second file");
linelen = 0;
getline (&header2[1], &linelen, p2);
if (getline (&header2[1], &linelen, p2) == -1)
error (EXIT_FAILURE, errno, "Failed to read patch header from second file");
linelen = 0;

fgetpos (p1, &at1);
Expand Down
21 changes: 11 additions & 10 deletions src/rediff.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,8 @@ static int rediff (const char *original, const char *edited, FILE *out)
pid_t child;
FILE *o;
FILE *m;
FILE *t = NULL;
FILE *diff_pipe = NULL;
FILE *meta_hunks = NULL;
char *line = NULL;
size_t linelen = 0;
unsigned long linenum = 0;
Expand Down Expand Up @@ -905,17 +906,17 @@ static int rediff (const char *original, const char *edited, FILE *out)
last->num_lines = linenum - last->line_in_diff + 1;

/* Run diff between original and edited. */
t = xpipe (DIFF, &child, "r", DIFF, "-U0",
diff_pipe = xpipe (DIFF, &child, "r", DIFF, "-U0",
original, edited, NULL);
m = xtmpfile ();
if (m) {
size_t buffer_size = 10000;
char *buffer = xmalloc (buffer_size);
while (!feof (t)) {
size_t got = fread (buffer, 1, buffer_size, t);
while (!feof (diff_pipe)) {
size_t got = fread (buffer, 1, buffer_size, diff_pipe);
fwrite (buffer, 1, got, m);
}
fclose (t);
fclose (diff_pipe);
waitpid (child, NULL, 0);
rewind (m);
free (buffer);
Expand Down Expand Up @@ -978,7 +979,7 @@ static int rediff (const char *original, const char *edited, FILE *out)
if (current_hunk) {
line_offset += show_modified_hunk
(&current_hunk, line_offset,
t, o, out);
meta_hunks, o, out);
current_hunk = current_hunk->next;
}

Expand All @@ -989,26 +990,26 @@ static int rediff (const char *original, const char *edited, FILE *out)

/* This meta hunk is the first pertaining to
* the hunk in the original. */
t = xtmpfile ();
meta_hunks = xtmpfile ();
}

current_hunk = which;

/* Append the meta hunk to a temporary file. */
fputs (line, t);
fputs (line, meta_hunks);
while (!feof (m)) {
if (getline (&line, &linelen, m) == -1)
break;
if (!strncmp (line, "@@ ", 3))
break;
fputs (line, t);
fputs (line, meta_hunks);
}
}

/* Now display the remaining hunks, adjusting offsets. */
if (current_hunk) {
line_offset += show_modified_hunk (&current_hunk, line_offset,
t, o, out);
meta_hunks, o, out);
current_hunk = current_hunk->next;
if (current_hunk)
copy_to (current_hunk, NULL, &line_offset, o, out, 0);
Expand Down
12 changes: 8 additions & 4 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ FILE * xpipe(const char * cmd, pid_t *pid, const char *mode, ...)
va_end(ap);

fflush (NULL);
pipe (fildes);
if (pipe (fildes) == -1)
error (EXIT_FAILURE, errno, "pipe failed");
child = fork ();
if (child == -1) {
perror ("fork");
Expand All @@ -312,14 +313,17 @@ FILE * xpipe(const char * cmd, pid_t *pid, const char *mode, ...)
if (*mode == 'r') {
close (fildes[0]);
close (1);
dup (fildes[1]);
if (dup (fildes[1]) == -1)
error (EXIT_FAILURE, errno, "dup failed");
close (fildes[1]);
} else {
close (fildes[1]);
close (1);
dup(2);
if (dup(2) == -1)
error (EXIT_FAILURE, errno, "dup failed");
close (0);
dup (fildes[0]);
if (dup (fildes[0]) == -1)
error (EXIT_FAILURE, errno, "dup failed");
close (fildes[0]);
}
execvp (cmd, argv);
Expand Down