Commit 4a8520aa6bbd7d1193aabc34e80edce3d18c0239

Stefan Sperling 2018-10-18T22:32:17

use a constant for max diff context size

diff --git a/got/got.c b/got/got.c
index 9724740..7ea9071 100644
--- a/got/got.c
+++ b/got/got.c
@@ -460,7 +460,8 @@ cmd_log(int argc, char *argv[])
 			start_commit = optarg;
 			break;
 		case 'C':
-			diff_context = strtonum(optarg, 1, INT_MAX, &errstr);
+			diff_context = strtonum(optarg, 0, GOT_DIFF_MAX_CONTEXT,
+			    &errstr);
 			if (errstr != NULL)
 				err(1, "-C option %s", errstr);
 			break;
diff --git a/include/got_diff.h b/include/got_diff.h
index 2d8ae7f..a817a1e 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -63,3 +63,5 @@ const struct got_error *got_diff_objects_as_trees(struct got_object *,
  */
 const struct got_error *got_diff_objects_as_commits(struct got_object *,
     struct got_object *, int, struct got_repository *, FILE *);
+
+#define GOT_DIFF_MAX_CONTEXT	64
diff --git a/lib/diffreg.c b/lib/diffreg.c
index b2fe324..54ebb2f 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -280,7 +280,7 @@ got_diffreg(int *rval, FILE *f1, FILE *f2, int flags,
 	ds->lastline = 0;
 	ds->lastmatchline = 0;
 	ds->context_vec_ptr = ds->context_vec_start - 1;
-	ds->max_context = 64;
+	ds->max_context = GOT_DIFF_MAX_CONTEXT;
 	if (flags & D_IGNORECASE)
 		ds->chrtran = cup2low;
 	else
diff --git a/tog/tog.c b/tog/tog.c
index 82f68df..2d26c2e 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1795,7 +1795,7 @@ input_diff_view(struct tog_view **new_view, struct tog_view **dead_view,
 			}
 			break;
 		case ']':
-			if (s->diff_context < INT_MAX) {
+			if (s->diff_context < GOT_DIFF_MAX_CONTEXT) {
 				s->diff_context++;
 				err = create_diff(s);
 			}