got patch: use ints for line offsets instead of longs ints have the advantage that their size is more likely to be the same across the various architecture supported by OpenBSD, thus introducing less possible differences. INT_MAX is still (at least) a few order of magnitudes higher than the patches we dealt with (even abnormal ones.) suggested by stsp@
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index c6c29a0..cc6e50c 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -618,10 +618,10 @@ struct got_imsg_patch {
* Structure for GOT_IMSG_PATCH_HUNK data.
*/
struct got_imsg_patch_hunk {
- long oldfrom;
- long oldlines;
- long newfrom;
- long newlines;
+ int oldfrom;
+ int oldlines;
+ int newfrom;
+ int newlines;
};
struct got_remote_repo;
diff --git a/lib/patch.c b/lib/patch.c
index 7e310ae..133f045 100644
--- a/lib/patch.c
+++ b/lib/patch.c
@@ -54,13 +54,13 @@
struct got_patch_hunk {
STAILQ_ENTRY(got_patch_hunk) entries;
const struct got_error *err;
- long offset;
+ int offset;
int old_nonl;
int new_nonl;
- long old_from;
- long old_lines;
- long new_from;
- long new_lines;
+ int old_from;
+ int old_lines;
+ int new_from;
+ int new_lines;
size_t len;
size_t cap;
char **lines;
@@ -337,7 +337,7 @@ copy(FILE *tmp, FILE *orig, off_t copypos, off_t pos)
}
static const struct got_error *
-locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, long *lineno)
+locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, int *lineno)
{
const struct got_error *err = NULL;
char *line = NULL;
@@ -345,7 +345,7 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, off_t *pos, long *lineno)
size_t linesize = 0;
ssize_t linelen;
off_t match = -1;
- long match_lineno = -1;
+ int match_lineno = -1;
for (;;) {
linelen = getline(&line, &linesize, orig);
@@ -426,7 +426,7 @@ done:
}
static const struct got_error *
-apply_hunk(FILE *tmp, struct got_patch_hunk *h, long *lineno)
+apply_hunk(FILE *tmp, struct got_patch_hunk *h, int *lineno)
{
size_t i, new = 0;
@@ -461,7 +461,7 @@ patch_file(struct got_patch *p, const char *path, FILE *tmp, int nop,
const struct got_error *err = NULL;
struct got_patch_hunk *h;
struct stat sb;
- long lineno = 0;
+ int lineno = 0;
FILE *orig;
off_t copypos, pos;
char *line = NULL;
@@ -698,7 +698,7 @@ reverse_patch(struct got_patch *p)
{
struct got_patch_hunk *h;
size_t i;
- long tmp;
+ int tmp;
STAILQ_FOREACH(h, &p->head, entries) {
tmp = h->old_from;
diff --git a/libexec/got-read-patch/got-read-patch.c b/libexec/got-read-patch/got-read-patch.c
index 0e9106a..23212ab 100644
--- a/libexec/got-read-patch/got-read-patch.c
+++ b/libexec/got-read-patch/got-read-patch.c
@@ -198,7 +198,7 @@ find_patch(int *done, FILE *fp)
}
static const struct got_error *
-strtolnum(char **str, long *n)
+strtolnum(char **str, int *n)
{
char *p, c;
const char *errstr;
@@ -209,7 +209,7 @@ strtolnum(char **str, long *n)
c = *p;
*p = '\0';
- *n = strtonum(*str, 0, LONG_MAX, &errstr);
+ *n = strtonum(*str, 0, INT_MAX, &errstr);
if (errstr != NULL)
return got_error(GOT_ERR_PATCH_MALFORMED);
@@ -264,10 +264,10 @@ parse_hdr(char *s, int *done, struct got_imsg_patch_hunk *hdr)
if (*s != '@')
return got_error(GOT_ERR_PATCH_MALFORMED);
- if (hdr->oldfrom >= LONG_MAX - hdr->oldlines ||
- hdr->newfrom >= LONG_MAX - hdr->newlines ||
+ if (hdr->oldfrom >= INT_MAX - hdr->oldlines ||
+ hdr->newfrom >= INT_MAX - hdr->newlines ||
/* not so sure about this one */
- hdr->oldlines >= LONG_MAX - hdr->newlines - 1 ||
+ hdr->oldlines >= INT_MAX - hdr->newlines - 1 ||
(hdr->oldlines == 0 && hdr->newlines == 0))
return got_error(GOT_ERR_PATCH_MALFORMED);
@@ -340,7 +340,7 @@ parse_hunk(FILE *fp, int *done)
char *line = NULL, ch;
size_t linesize = 0;
ssize_t linelen;
- long leftold, leftnew;
+ int leftold, leftnew;
linelen = getline(&line, &linesize, fp);
if (linelen == -1) {