commit 8ebb3daa7771365ed3667ee1d17a090556495847 from: Omar Polo via: Thomas Adam date: Thu Jun 23 14:09:34 2022 UTC 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@ commit - 06227823b7e714dc42c8b3088e152be044e03b46 commit + 8ebb3daa7771365ed3667ee1d17a090556495847 blob - 7291e46e9b4f572371088a669a482534178732e7 blob + 7c79ce98e69f74eddb8e63cbcc86fba3f740c598 --- lib/got_lib_privsep.h +++ 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; blob - 1eb449f5b54c82290ced9fb2863172a511a5c43a blob + 5716ef32857193fa104d1a5ffb75f6366fdf6807 --- lib/patch.c +++ lib/patch.c @@ -51,13 +51,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; @@ -334,7 +334,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; @@ -342,7 +342,7 @@ locate_hunk(FILE *orig, struct got_patch_hunk *h, off_ 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); @@ -423,7 +423,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; @@ -458,7 +458,7 @@ patch_file(struct got_patch *p, const char *path, FILE 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; @@ -695,7 +695,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; blob - 054a99b50f0835f1ab90b05dabba1586da811977 blob + e3fb875dfb206b0f0ca027d9645c0b7bbfafd410 --- libexec/got-read-patch/got-read-patch.c +++ libexec/got-read-patch/got-read-patch.c @@ -197,7 +197,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; @@ -208,7 +208,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); @@ -263,10 +263,10 @@ parse_hdr(char *s, int *done, struct got_imsg_patch_hu 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); @@ -339,7 +339,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) {