diff --git a/Makefile b/Makefile index 9999d179c28e3d..f3074064b02eb8 100644 --- a/Makefile +++ b/Makefile @@ -758,6 +758,7 @@ TEST_BUILTINS_OBJS += test-xml-encode.o TEST_BUILTINS_OBJS += test-wildmatch.o TEST_BUILTINS_OBJS += test-windows-named-pipe.o TEST_BUILTINS_OBJS += test-write-cache.o +TEST_BUILTINS_OBJS += test-zlib-compile-flags.o # Do not add more tests here unless they have extra dependencies. Add # them in TEST_BUILTINS_OBJS above. diff --git a/apply.c b/apply.c index 1acaad1a0d510a..30536ea56e415d 100644 --- a/apply.c +++ b/apply.c @@ -177,9 +177,9 @@ static void set_default_whitespace_mode(struct apply_state *state) * of context lines. */ struct fragment { - unsigned long leading, trailing; - unsigned long oldpos, oldlines; - unsigned long newpos, newlines; + size_t leading, trailing; + size_t oldpos, oldlines; + size_t newpos, newlines; /* * 'patch' is usually borrowed from buf in apply_patch(), * but some codepaths store an allocated buffer. @@ -423,9 +423,9 @@ static int read_patch_file(struct strbuf *sb, int fd) return 0; } -static unsigned long linelen(const char *buffer, unsigned long size) +static size_t linelen(const char *buffer, size_t size) { - unsigned long len = 0; + size_t len = 0; while (size--) { len++; if (*buffer++ == '\n') @@ -1321,7 +1321,7 @@ static int parse_git_header(struct apply_state *state, unsigned int size, struct patch *patch) { - unsigned long offset; + size_t offset; /* A git diff has explicit new/delete information, so we don't guess */ patch->is_new = 0; @@ -1391,7 +1391,7 @@ static int parse_git_header(struct apply_state *state, return offset; } -static int parse_num(const char *line, unsigned long *p) +static int parse_num(const char *line, size_t *p) { char *ptr; @@ -1402,7 +1402,7 @@ static int parse_num(const char *line, unsigned long *p) } static int parse_range(const char *line, int len, int offset, const char *expect, - unsigned long *p1, unsigned long *p2) + size_t *p1, size_t *p2) { int digits, ex; @@ -1517,11 +1517,11 @@ static int parse_fragment_header(const char *line, int len, struct fragment *fra */ static int find_header(struct apply_state *state, const char *line, - unsigned long size, + size_t size, int *hdrsize, struct patch *patch) { - unsigned long offset, len; + size_t offset, len; patch->is_toplevel_relative = 0; patch->is_rename = patch->is_copy = 0; @@ -1529,7 +1529,7 @@ static int find_header(struct apply_state *state, patch->old_mode = patch->new_mode = 0; patch->old_name = patch->new_name = NULL; for (offset = 0; size > 0; offset += len, size -= len, line += len, state->linenr++) { - unsigned long nextlen; + size_t nextlen; len = linelen(line, size); if (!len) @@ -1667,14 +1667,14 @@ static void check_old_for_crlf(struct patch *patch, const char *line, int len) */ static int parse_fragment(struct apply_state *state, const char *line, - unsigned long size, + size_t size, struct patch *patch, struct fragment *fragment) { int added, deleted; int len = linelen(line, size), offset; - unsigned long oldlines, newlines; - unsigned long leading, trailing; + size_t oldlines, newlines; + size_t leading, trailing; offset = parse_fragment_header(line, len, fragment); if (offset < 0) @@ -1789,11 +1789,11 @@ static int parse_fragment(struct apply_state *state, */ static int parse_single_patch(struct apply_state *state, const char *line, - unsigned long size, + size_t size, struct patch *patch) { - unsigned long offset = 0; - unsigned long oldlines = 0, newlines = 0, context = 0; + size_t offset = 0; + size_t oldlines = 0, newlines = 0, context = 0; struct fragment **fragp = &patch->fragments; while (size > 4 && !memcmp(line, "@@ -", 4)) { @@ -1864,8 +1864,8 @@ static inline int metadata_changes(struct patch *patch) patch->old_mode != patch->new_mode); } -static char *inflate_it(const void *data, unsigned long size, - unsigned long inflated_size) +static char *inflate_it(const void *data, size_t size, + size_t inflated_size) { git_zstream stream; void *out; @@ -1894,7 +1894,7 @@ static char *inflate_it(const void *data, unsigned long size, */ static struct fragment *parse_binary_hunk(struct apply_state *state, char **buf_p, - unsigned long *sz_p, + size_t *sz_p, int *status_p, int *used_p) { @@ -1911,10 +1911,10 @@ static struct fragment *parse_binary_hunk(struct apply_state *state, * to 1-26 bytes, and 'a'-'z' corresponds to 27-52 bytes. */ int llen, used; - unsigned long size = *sz_p; + size_t size = *sz_p; char *buffer = *buf_p; int patch_method; - unsigned long origlen; + size_t origlen; char *data = NULL; int hunk_size = 0; struct fragment *frag; @@ -2006,7 +2006,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state, */ static int parse_binary(struct apply_state *state, char *buffer, - unsigned long size, + size_t size, struct patch *patch) { /* @@ -2123,7 +2123,7 @@ static int use_patch(struct apply_state *state, struct patch *p) * the number of bytes consumed otherwise, * so that the caller can call us again for the next patch. */ -static int parse_chunk(struct apply_state *state, char *buffer, unsigned long size, struct patch *patch) +static int parse_chunk(struct apply_state *state, char *buffer, size_t size, struct patch *patch) { int hdrsize, patchsize; int offset = find_header(state, buffer, size, &hdrsize, patch); @@ -2153,7 +2153,7 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si if (!patchsize) { static const char git_binary[] = "GIT binary patch\n"; int hd = hdrsize + offset; - unsigned long llen = linelen(buffer + hd, size - hd); + size_t llen = linelen(buffer + hd, size - hd); if (llen == sizeof(git_binary) - 1 && !memcmp(git_binary, buffer + hd, llen)) { @@ -2397,7 +2397,7 @@ static void update_pre_post_images(struct image *preimage, static int line_by_line_fuzzy_match(struct image *img, struct image *preimage, struct image *postimage, - unsigned long current, + size_t current, int current_lno, int preimage_limit) { @@ -2466,7 +2466,7 @@ static int match_fragment(struct apply_state *state, struct image *img, struct image *preimage, struct image *postimage, - unsigned long current, + size_t current, int current_lno, unsigned ws_rule, int match_beginning, int match_end) @@ -2677,7 +2677,7 @@ static int find_pos(struct apply_state *state, int match_beginning, int match_end) { int i; - unsigned long backwards, forwards, current; + size_t backwards, forwards, current; int backwards_lno, forwards_lno, current_lno; /* @@ -2861,7 +2861,7 @@ static int apply_one_fragment(struct apply_state *state, int new_blank_lines_at_end = 0; int found_new_blank_lines_at_end = 0; int hunk_linenr = frag->linenr; - unsigned long leading, trailing; + size_t leading, trailing; int pos, applied_pos; struct image preimage; struct image postimage; @@ -3085,9 +3085,9 @@ static int apply_one_fragment(struct apply_state *state, */ if ((leading != frag->leading || trailing != frag->trailing) && state->apply_verbosity > verbosity_silent) - fprintf_ln(stderr, _("Context reduced to (%ld/%ld)" + fprintf_ln(stderr, _("Context reduced to (%"PRIuMAX"/%"PRIuMAX")" " to apply fragment at %d"), - leading, trailing, applied_pos+1); + (uintmax_t)leading, (uintmax_t)trailing, applied_pos+1); update_image(state, img, applied_pos, &preimage, &postimage); } else { if (state->apply_verbosity > verbosity_normal) @@ -3109,7 +3109,7 @@ static int apply_binary_fragment(struct apply_state *state, struct patch *patch) { struct fragment *fragment = patch->fragments; - unsigned long len; + size_t len; void *dst; if (!fragment) @@ -3199,7 +3199,7 @@ static int apply_binary(struct apply_state *state, if (has_object_file(&oid)) { /* We already have the postimage */ enum object_type type; - unsigned long size; + size_t size; char *result; result = read_object_file(&oid, &type, &size); @@ -3244,7 +3244,7 @@ static int apply_fragments(struct apply_state *state, struct image *img, struct while (frag) { nth++; if (apply_one_fragment(state, img, frag, inaccurate_eof, ws_rule, nth)) { - error(_("patch failed: %s:%ld"), name, frag->oldpos); + error(_("patch failed: %s:%"PRIuMAX), name, (uintmax_t)frag->oldpos); if (!state->apply_with_reject) return -1; frag->rejected = 1; @@ -3261,7 +3261,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns strbuf_addf(buf, "Subproject commit %s\n", oid_to_hex(oid)); } else { enum object_type type; - unsigned long sz; + size_t sz; char *result; result = read_object_file(oid, &type, &sz); @@ -4290,7 +4290,7 @@ static int add_index_file(struct apply_state *state, const char *path, unsigned mode, void *buf, - unsigned long size) + size_t size) { struct stat st; struct cache_entry *ce; @@ -4344,7 +4344,7 @@ static int add_index_file(struct apply_state *state, */ static int try_create_file(struct apply_state *state, const char *path, unsigned int mode, const char *buf, - unsigned long size) + size_t size) { int fd, res; struct strbuf nbuf = STRBUF_INIT; @@ -4395,7 +4395,7 @@ static int create_one_file(struct apply_state *state, char *path, unsigned mode, const char *buf, - unsigned long size) + size_t size) { int res; @@ -4487,7 +4487,7 @@ static int create_file(struct apply_state *state, struct patch *patch) { char *path = patch->new_name; unsigned mode = patch->new_mode; - unsigned long size = patch->resultsize; + size_t size = patch->resultsize; char *buf = patch->result; if (!mode) diff --git a/archive-tar.c b/archive-tar.c index 4138a5f5be9c9b..be0c0acee2e592 100644 --- a/archive-tar.c +++ b/archive-tar.c @@ -13,7 +13,7 @@ #define BLOCKSIZE (RECORDSIZE * 20) static char block[BLOCKSIZE]; -static unsigned long offset; +static size_t offset; static int tar_umask = 002; @@ -63,12 +63,12 @@ static void write_if_needed(void) * queues up writes, so that all our write(2) calls write exactly one * full block; pads writes to RECORDSIZE */ -static void do_write_blocked(const void *data, unsigned long size) +static void do_write_blocked(const void *data, size_t size) { const char *buf = data; if (offset) { - unsigned long chunk = BLOCKSIZE - offset; + size_t chunk = BLOCKSIZE - offset; if (size < chunk) chunk = size; memcpy(block + offset, buf, chunk); @@ -90,7 +90,7 @@ static void do_write_blocked(const void *data, unsigned long size) static void finish_record(void) { - unsigned long tail; + size_t tail; tail = offset % RECORDSIZE; if (tail) { memset(block + offset, 0, RECORDSIZE - tail); @@ -99,7 +99,7 @@ static void finish_record(void) write_if_needed(); } -static void write_blocked(const void *data, unsigned long size) +static void write_blocked(const void *data, size_t size) { do_write_blocked(data, size); finish_record(); @@ -128,7 +128,7 @@ static int stream_blocked(const struct object_id *oid) { struct git_istream *st; enum object_type type; - unsigned long sz; + size_t sz; char buf[BLOCKSIZE]; ssize_t readlen; @@ -211,7 +211,7 @@ static size_t get_path_prefix(const char *path, size_t pathlen, size_t maxlen) static void prepare_header(struct archiver_args *args, struct ustar_header *header, - unsigned int mode, unsigned long size) + unsigned int mode, size_t size) { xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777); xsnprintf(header->size, sizeof(header->size), "%011"PRIoMAX , S_ISREG(mode) ? (uintmax_t)size : (uintmax_t)0); @@ -232,7 +232,7 @@ static void prepare_header(struct archiver_args *args, static void write_extended_header(struct archiver_args *args, const struct object_id *oid, - const void *buffer, unsigned long size) + const void *buffer, size_t size) { struct ustar_header header; unsigned int mode; @@ -253,7 +253,7 @@ static int write_tar_entry(struct archiver_args *args, struct ustar_header header; struct strbuf ext_header = STRBUF_INIT; unsigned int old_mode = mode; - unsigned long size, size_in_header; + size_t size, size_in_header; void *buffer; int err = 0; diff --git a/archive-zip.c b/archive-zip.c index 4d66b5be6e889e..3d49bde1eccdb4 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -297,7 +297,7 @@ static int write_zip_entry(struct archiver_args *args, void *buffer; struct git_istream *stream = NULL; unsigned long flags = 0; - unsigned long size; + size_t size; int is_binary = -1; const char *path_without_prefix = path + args->baselen; unsigned int creator_version = 0; @@ -352,7 +352,7 @@ static int write_zip_entry(struct archiver_args *args, if (!buffer) return error(_("cannot read %s"), oid_to_hex(oid)); - crc = crc32(crc, buffer, size); + crc = xcrc32(crc, buffer, size); is_binary = entry_is_binary(args->repo->index, path_without_prefix, buffer, size); @@ -428,7 +428,7 @@ static int write_zip_entry(struct archiver_args *args, readlen = read_istream(stream, buf, sizeof(buf)); if (readlen <= 0) break; - crc = crc32(crc, buf, readlen); + crc = xcrc32(crc, buf, readlen); if (is_binary == -1) is_binary = entry_is_binary(args->repo->index, path_without_prefix, @@ -461,7 +461,7 @@ static int write_zip_entry(struct archiver_args *args, readlen = read_istream(stream, buf, sizeof(buf)); if (readlen <= 0) break; - crc = crc32(crc, buf, readlen); + crc = xcrc32(crc, buf, readlen); if (is_binary == -1) is_binary = entry_is_binary(args->repo->index, path_without_prefix, diff --git a/archive.c b/archive.c index 53141c1f0ee12b..8b18c72ac70bb4 100644 --- a/archive.c +++ b/archive.c @@ -73,7 +73,7 @@ static void format_subst(const struct commit *commit, void *object_file_to_archive(const struct archiver_args *args, const char *path, const struct object_id *oid, unsigned int mode, enum object_type *type, - unsigned long *sizep) + size_t *sizep) { void *buffer; const struct commit *commit = args->convert ? args->commit : NULL; diff --git a/archive.h b/archive.h index e60e3dd31c79f1..c6dea7a4d8b6fc 100644 --- a/archive.h +++ b/archive.h @@ -52,8 +52,8 @@ typedef int (*write_archive_entry_fn_t)(struct archiver_args *args, int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry); void *object_file_to_archive(const struct archiver_args *args, - const char *path, const struct object_id *oid, - unsigned int mode, enum object_type *type, - unsigned long *sizep); + const char *path, const struct object_id *oid, + unsigned int mode, enum object_type *type, + size_t *sizep); #endif /* ARCHIVE_H */ diff --git a/bisect.c b/bisect.c index e87ac29a51be41..7ca069225d104a 100644 --- a/bisect.c +++ b/bisect.c @@ -137,7 +137,7 @@ static void show_list(const char *debug, int counted, int nr, struct commit *commit = p->item; unsigned flags = commit->object.flags; enum object_type type; - unsigned long size; + size_t size; char *buf = read_object_file(&commit->object.oid, &type, &size); const char *subject_start; diff --git a/blame.c b/blame.c index 145eaf2faf9cf5..c14b79fd22cfa7 100644 --- a/blame.c +++ b/blame.c @@ -223,7 +223,7 @@ static struct commit *fake_working_tree_commit(struct repository *r, struct stat st; const char *read_from; char *buf_ptr; - unsigned long buf_len; + size_t buf_len; if (contents_from) { if (stat(contents_from, &st) < 0) @@ -320,7 +320,7 @@ static void fill_origin_blob(struct diff_options *opt, { if (!o->file.ptr) { enum object_type type; - unsigned long file_size; + size_t file_size; (*num_read_blob)++; if (opt->flags.allow_textconv && diff --git a/blame.h b/blame.h index d62f80fa74c440..1d47e1c0aa21d6 100644 --- a/blame.h +++ b/blame.h @@ -112,7 +112,7 @@ struct blame_scoreboard { * indexed with scoreboard.lineno[blame_entry.lno]. */ const char *final_buf; - unsigned long final_buf_size; + size_t final_buf_size; /* linked list of blames */ struct blame_entry *ent; diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 0f092382e175cf..dc502075730016 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -31,7 +31,7 @@ static const char *force_path; static int filter_object(const char *path, unsigned mode, const struct object_id *oid, - char **buf, unsigned long *size) + char **buf, size_t *size) { enum object_type type; @@ -64,7 +64,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, struct object_id oid; enum object_type type; char *buf; - unsigned long size; + size_t size; struct object_context obj_context; struct object_info oi = OBJECT_INFO_INIT; struct strbuf sb = STRBUF_INIT; @@ -191,7 +191,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, struct expand_data { struct object_id oid; enum object_type type; - unsigned long size; + size_t size; off_t disk_size; const char *rest; struct object_id delta_base_oid; @@ -303,7 +303,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d fflush(stdout); if (opt->cmdmode) { char *contents; - unsigned long size; + size_t size; if (!data->rest) die("missing path for '%s'", oid_to_hex(oid)); @@ -334,7 +334,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d } else { enum object_type type; - unsigned long size; + size_t size; void *contents; contents = read_object_file(oid, &type, &size); diff --git a/builtin/difftool.c b/builtin/difftool.c index 64156a43b482ec..7e3e431d03b9d1 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -299,7 +299,7 @@ static char *get_symlink(const struct object_id *oid, const char *path) data = strbuf_detach(&link, NULL); } else { enum object_type type; - unsigned long size; + size_t size; data = read_object_file(oid, &type, &size); if (!data) die(_("could not read object %s for symlink %s"), diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 9e283482efcfa6..09ce3b1996aada 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -226,7 +226,7 @@ static void show_progress(void) * There's no need to cache this result with anonymize_mem, since * we already handle blob content caching with marks. */ -static char *anonymize_blob(unsigned long *size) +static char *anonymize_blob(size_t *size) { static int counter; struct strbuf out = STRBUF_INIT; @@ -237,7 +237,7 @@ static char *anonymize_blob(unsigned long *size) static void export_blob(const struct object_id *oid) { - unsigned long size; + size_t size; enum object_type type; char *buf; struct object *object; @@ -707,7 +707,7 @@ static void handle_tail(struct object_array *commits, struct rev_info *revs, static void handle_tag(const char *name, struct tag *tag) { - unsigned long size; + size_t size; enum object_type type; char *buf; const char *tagger, *tagger_end, *message; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index a4615587fd7929..0f049ba87e2ffb 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -471,7 +471,7 @@ static void fmt_merge_msg_title(struct strbuf *out, static void fmt_tag_signature(struct strbuf *tagbuf, struct strbuf *sig, const char *buf, - unsigned long len) + size_t len) { const char *tag_body = strstr(buf, "\n\n"); if (tag_body) { @@ -493,7 +493,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out) for (i = 0; i < origins.nr; i++) { struct object_id *oid = origins.items[i].util; enum object_type type; - unsigned long size, len; + size_t size, len; char *buf = read_object_file(oid, &type, &size); struct strbuf sig = STRBUF_INIT; diff --git a/builtin/fsck.c b/builtin/fsck.c index d26fb0a04472b1..96cfd64fb68fa0 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -422,7 +422,7 @@ static void check_connectivity(void) } } -static int fsck_obj(struct object *obj, void *buffer, unsigned long size) +static int fsck_obj(struct object *obj, void *buffer, size_t size) { int err; @@ -470,7 +470,7 @@ static int fsck_obj(struct object *obj, void *buffer, unsigned long size) } static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, - unsigned long size, void *buffer, int *eaten) + size_t size, void *buffer, int *eaten) { /* * Note, buffer may be NULL if type is OBJ_BLOB. See @@ -625,7 +625,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data) { struct object *obj; enum object_type type; - unsigned long size; + size_t size; void *contents; int eaten; diff --git a/builtin/grep.c b/builtin/grep.c index 580fd38f41704b..97682a86438790 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -295,7 +295,7 @@ static int grep_cmd_config(const char *var, const char *value, void *cb) return st; } -static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, unsigned long *size) +static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, size_t *size) { void *data; @@ -452,7 +452,7 @@ static int grep_submodule(struct grep_opt *opt, struct object *object; struct tree_desc tree; void *data; - unsigned long size; + size_t size; struct strbuf base = STRBUF_INIT; object = parse_object_or_die(oid, oid_to_hex(oid)); @@ -583,7 +583,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, enum object_type type; struct tree_desc sub; void *data; - unsigned long size; + size_t size; data = lock_and_read_oid_file(&entry.oid, &type, &size); if (!data) @@ -618,7 +618,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) { struct tree_desc tree; void *data; - unsigned long size; + size_t size; struct strbuf base; int hit, len; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index ccf4eb7e9b3361..1e9c33f9e81a84 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -20,7 +20,7 @@ static const char index_pack_usage[] = struct object_entry { struct pack_idx_entry idx; - unsigned long size; + size_t size; unsigned char hdr_size; signed char type; signed char real_type; @@ -36,7 +36,7 @@ struct base_data { struct base_data *child; struct object_entry *obj; void *data; - unsigned long size; + size_t size; int ref_first, ref_last; int ofs_first, ofs_last; }; @@ -198,7 +198,7 @@ static unsigned check_object(struct object *obj) return 0; if (!(obj->flags & FLAG_CHECKED)) { - unsigned long size; + size_t size; int type = oid_object_info(the_repository, &obj->oid, &size); if (type <= 0) die(_("did not receive expected object %s"), @@ -278,7 +278,7 @@ static void use(int bytes) { if (bytes > input_len) die(_("used more bytes than were available")); - input_crc32 = crc32(input_crc32, input_buffer + input_offset, bytes); + input_crc32 = xcrc32(input_crc32, input_buffer + input_offset, bytes); input_len -= bytes; input_offset += bytes; @@ -420,7 +420,7 @@ static int is_delta_type(enum object_type type) return (type == OBJ_REF_DELTA || type == OBJ_OFS_DELTA); } -static void *unpack_entry_data(off_t offset, unsigned long size, +static void *unpack_entry_data(off_t offset, size_t size, enum object_type type, struct object_id *oid) { static char fixed_buf[8192]; @@ -461,8 +461,12 @@ static void *unpack_entry_data(off_t offset, unsigned long size, stream.avail_out = sizeof(fixed_buf); } } while (status == Z_OK); - if (stream.total_out != size || status != Z_STREAM_END) - bad_object(offset, _("inflate returned %d"), status); + if (stream.total_out != size) + // BUGS OUT HERE + bad_object(offset, _("stream.total_out != size: inflate returned %d"), status); + if (status != Z_STREAM_END) + // BUGS OUT HERE + bad_object(offset, _("status != Z_STREAM_END: inflate returned %d"), status); git_inflate_end(&stream); if (oid) the_hash_algo->final_fn(oid->hash, &c); @@ -475,9 +479,9 @@ static void *unpack_raw_entry(struct object_entry *obj, struct object_id *oid) { unsigned char *p; - unsigned long size, c; + size_t size, c; off_t base_offset; - unsigned shift; + size_t shift; void *data; obj->idx.offset = consumed_bytes; @@ -537,7 +541,7 @@ static void *unpack_raw_entry(struct object_entry *obj, } static void *unpack_data(struct object_entry *obj, - int (*consume)(const unsigned char *, unsigned long, void *), + int (*consume)(const unsigned char *, size_t, void *), void *cb_data) { off_t from = obj[0].idx.offset + obj[0].hdr_size; @@ -714,10 +718,10 @@ struct compare_data { struct object_entry *entry; struct git_istream *st; unsigned char *buf; - unsigned long buf_size; + size_t buf_size; }; -static int compare_objects(const unsigned char *buf, unsigned long size, +static int compare_objects(const unsigned char *buf, size_t size, void *cb_data) { struct compare_data *data = cb_data; @@ -749,7 +753,7 @@ static int check_collison(struct object_entry *entry) { struct compare_data data; enum object_type type; - unsigned long size; + size_t size; if (entry->size <= big_file_threshold || entry->type != OBJ_BLOB) return -1; @@ -769,7 +773,7 @@ static int check_collison(struct object_entry *entry) } static void sha1_object(const void *data, struct object_entry *obj_entry, - unsigned long size, enum object_type type, + size_t size, enum object_type type, const struct object_id *oid) { void *new_data = NULL; @@ -793,7 +797,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, if (collision_test_needed) { void *has_data; enum object_type has_type; - unsigned long has_size; + size_t has_size; read_lock(); has_type = oid_object_info(the_repository, oid, &has_size); if (has_type < 0) @@ -1296,11 +1300,11 @@ static int write_compressed(struct hashfile *f, void *in, unsigned int size) static struct object_entry *append_obj_to_pack(struct hashfile *f, const unsigned char *sha1, void *buf, - unsigned long size, enum object_type type) + size_t size, enum object_type type) { struct object_entry *obj = &objects[nr_objects++]; unsigned char header[10]; - unsigned long s = size; + size_t s = size; int n = 0; unsigned char c = (type << 4) | (s & 15); s >>= 4; @@ -1594,10 +1598,10 @@ static void read_idx_option(struct pack_idx_option *opts, const char *pack_name) static void show_pack_info(int stat_only) { int i, baseobjects = nr_objects - nr_ref_deltas - nr_ofs_deltas; - unsigned long *chain_histogram = NULL; + size_t *chain_histogram = NULL; if (deepest_delta) - chain_histogram = xcalloc(deepest_delta, sizeof(unsigned long)); + chain_histogram = xcalloc(deepest_delta, sizeof(size_t)); for (i = 0; i < nr_objects; i++) { struct object_entry *obj = &objects[i]; @@ -1627,11 +1631,11 @@ static void show_pack_info(int stat_only) for (i = 0; i < deepest_delta; i++) { if (!chain_histogram[i]) continue; - printf_ln(Q_("chain length = %d: %lu object", - "chain length = %d: %lu objects", + printf_ln(Q_("chain length = %d: %"PRIuMAX" object", + "chain length = %d: %"PRIuMAX" objects", chain_histogram[i]), i + 1, - chain_histogram[i]); + (uintmax_t)chain_histogram[i]); } } diff --git a/builtin/log.c b/builtin/log.c index 2a239b357bd3c7..7ae9b52c10412c 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -507,7 +507,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c struct object_id oidc; struct object_context obj_context; char *buf; - unsigned long size; + size_t size; fflush(rev->diffopt.file); if (!rev->diffopt.flags.textconv_set_via_cmdline || @@ -535,7 +535,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c static int show_tag_object(const struct object_id *oid, struct rev_info *rev) { - unsigned long size; + size_t size; enum object_type type; char *buf = read_object_file(oid, &type, &size); int offset = 0; diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 7cad3f24ebd084..b4ceca9e2576b4 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -94,7 +94,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, if (ls_options & LS_SHOW_SIZE) { char size_text[24]; if (!strcmp(type, blob_type)) { - unsigned long size; + size_t size; if (oid_object_info(the_repository, oid, &size) == OBJ_BAD) xsnprintf(size_text, sizeof(size_text), "BAD"); diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 794d3464a0284d..473ca5bea13211 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -57,7 +57,7 @@ static const char *explanation(struct merge_list *entry) return "removed in remote"; } -static void *result(struct merge_list *entry, unsigned long *size) +static void *result(struct merge_list *entry, size_t *size) { enum object_type type; struct blob *base, *our, *their; @@ -82,7 +82,7 @@ static void *result(struct merge_list *entry, unsigned long *size) base, our, their, size); } -static void *origin(struct merge_list *entry, unsigned long *size) +static void *origin(struct merge_list *entry, size_t *size) { enum object_type type; while (entry) { @@ -104,7 +104,7 @@ static int show_outf(void *priv_, mmbuffer_t *mb, int nbuf) static void show_diff(struct merge_list *entry) { - unsigned long size; + size_t size; mmfile_t src, dst; xpparam_t xpp; xdemitconf_t xecfg; diff --git a/builtin/mktag.c b/builtin/mktag.c index ab9468713b2ff0..111cb8f6f74f51 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -25,7 +25,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type) { int ret = -1; enum object_type type; - unsigned long size; + size_t size; void *buffer = read_object_file(oid, &type, &size); const struct object_id *repl = lookup_replace_object(the_repository, oid); @@ -37,7 +37,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type) return ret; } -static int verify_tag(char *buffer, unsigned long size) +static int verify_tag(char *buffer, size_t size) { int typelen; char type[20]; diff --git a/builtin/notes.c b/builtin/notes.c index 02e97f55c5a01b..5f232d5e66f95b 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -122,7 +122,7 @@ static int list_each_note(const struct object_id *object_oid, static void copy_obj_to_fd(int fd, const struct object_id *oid) { - unsigned long size; + size_t size; enum object_type type; char *buf = read_object_file(oid, &type, &size); if (buf) { @@ -252,7 +252,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset) char *buf; struct object_id object; enum object_type type; - unsigned long len; + size_t len; BUG_ON_OPT_NEG(unset); @@ -616,7 +616,7 @@ static int append_edit(int argc, const char **argv, const char *prefix) if (note && !edit) { /* Append buf to previous note contents */ - unsigned long size; + size_t size; enum object_type type; char *prev_buf = read_object_file(note, &type, &size); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 41d7fc59830c09..ef199686d2f94a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -81,7 +81,7 @@ static struct pack_idx_option pack_idx_opts; static const char *base_name; static int progress = 1; static int window = 10; -static unsigned long pack_size_limit; +static size_t pack_size_limit; static int depth = 50; static int delta_search_threads; static int pack_to_stdout; @@ -103,11 +103,11 @@ static int exclude_promisor_objects; static int use_delta_islands; -static unsigned long delta_cache_size = 0; -static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE; -static unsigned long cache_max_small_delta_size = 1000; +static size_t delta_cache_size = 0; +static size_t max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE; +static size_t cache_max_small_delta_size = 1000; -static unsigned long window_memory_limit = 0; +static size_t window_memory_limit = 0; static struct list_objects_filter_options filter_options; @@ -144,7 +144,7 @@ static void index_commit_for_bitmap(struct commit *commit) static void *get_delta(struct object_entry *entry) { - unsigned long size, base_size, delta_size; + size_t size, base_size, delta_size; void *buf, *base_buf, *delta_buf; enum object_type type; @@ -170,11 +170,11 @@ static void *get_delta(struct object_entry *entry) return delta_buf; } -static unsigned long do_compress(void **pptr, unsigned long size) +static size_t do_compress(void **pptr, size_t size) { git_zstream stream; void *in, *out; - unsigned long maxsize; + size_t maxsize; git_deflate_init(&stream, pack_compression_level); maxsize = git_deflate_bound(&stream, size); @@ -195,13 +195,13 @@ static unsigned long do_compress(void **pptr, unsigned long size) return stream.total_out; } -static unsigned long write_large_blob_data(struct git_istream *st, struct hashfile *f, +static size_t write_large_blob_data(struct git_istream *st, struct hashfile *f, const struct object_id *oid) { git_zstream stream; unsigned char ibuf[1024 * 16]; unsigned char obuf[1024 * 16]; - unsigned long olen = 0; + size_t olen = 0; git_deflate_init(&stream, pack_compression_level); @@ -242,7 +242,7 @@ static int check_pack_inflate(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, - unsigned long expect) + size_t expect) { git_zstream stream; unsigned char fakebuf[4096], *in; @@ -271,12 +271,12 @@ static void copy_pack_data(struct hashfile *f, off_t len) { unsigned char *in; - unsigned long avail; + size_t avail; while (len) { in = use_pack(p, w_curs, offset, &avail); if (avail > len) - avail = (unsigned long)len; + avail = xsize_t(len); hashwrite(f, in, avail); offset += avail; len -= avail; @@ -284,10 +284,10 @@ static void copy_pack_data(struct hashfile *f, } /* Return 0 if we will bust the pack-size limit */ -static unsigned long write_no_reuse_object(struct hashfile *f, struct object_entry *entry, - unsigned long limit, int usable_delta) +static size_t write_no_reuse_object(struct hashfile *f, struct object_entry *entry, + size_t limit, int usable_delta) { - unsigned long size, datalen; + size_t size, datalen; unsigned char header[MAX_PACK_OBJECT_HEADER], dheader[MAX_PACK_OBJECT_HEADER]; unsigned hdrlen; @@ -396,7 +396,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent /* Return 0 if we will bust the pack-size limit */ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry, - unsigned long limit, int usable_delta) + size_t limit, int usable_delta) { struct packed_git *p = IN_PACK(entry); struct pack_window *w_curs = NULL; @@ -408,7 +408,7 @@ static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry, dheader[MAX_PACK_OBJECT_HEADER]; unsigned hdrlen; const unsigned hashsz = the_hash_algo->rawsz; - unsigned long entry_size = SIZE(entry); + size_t entry_size = SIZE(entry); if (DELTA(entry)) type = (allow_ofs_delta && DELTA(entry)->idx.offset) ? @@ -479,7 +479,7 @@ static off_t write_object(struct hashfile *f, struct object_entry *entry, off_t write_offset) { - unsigned long limit; + size_t limit; off_t len; int usable_delta, to_reuse; @@ -1212,7 +1212,7 @@ struct pbase_tree_cache { int ref; int temporary; void *tree_data; - unsigned long tree_size; + size_t tree_size; }; static struct pbase_tree_cache *(pbase_tree_cache[256]); @@ -1239,7 +1239,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid) { struct pbase_tree_cache *ent, *nent; void *data; - unsigned long size; + size_t size; enum object_type type; int neigh; int my_ix = pbase_tree_cache_ix(oid); @@ -1422,7 +1422,7 @@ static void add_preferred_base(struct object_id *oid) { struct pbase_tree *it; void *data; - unsigned long size; + size_t size; struct object_id tree_oid; if (window <= num_preferred_base++) @@ -1526,19 +1526,19 @@ static int can_reuse_delta(const unsigned char *base_sha1, static void check_object(struct object_entry *entry) { - unsigned long canonical_size; + size_t canonical_size; if (IN_PACK(entry)) { struct packed_git *p = IN_PACK(entry); struct pack_window *w_curs = NULL; const unsigned char *base_ref = NULL; struct object_entry *base_entry; - unsigned long used, used_0; - unsigned long avail; + size_t used, used_0; + size_t avail; off_t ofs; unsigned char *buf, c; enum object_type type; - unsigned long in_pack_size; + size_t in_pack_size; buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail); @@ -1704,7 +1704,7 @@ static void drop_reused_delta(struct object_entry *entry) unsigned *idx = &to_pack.objects[entry->delta_idx - 1].delta_child_idx; struct object_info oi = OBJECT_INFO_INIT; enum object_type type; - unsigned long size; + size_t size; while (*idx) { struct object_entry *oe = &to_pack.objects[*idx - 1]; @@ -1907,8 +1907,8 @@ static int type_size_sort(const void *_a, const void *_b) const struct object_entry *b = *(struct object_entry **)_b; const enum object_type a_type = oe_type(a); const enum object_type b_type = oe_type(b); - const unsigned long a_size = SIZE(a); - const unsigned long b_size = SIZE(b); + const size_t a_size = SIZE(a); + const size_t b_size = SIZE(b); if (a_type > b_type) return -1; @@ -1941,8 +1941,8 @@ struct unpacked { unsigned depth; }; -static int delta_cacheable(unsigned long src_size, unsigned long trg_size, - unsigned long delta_size) +static int delta_cacheable(size_t src_size, size_t trg_size, + size_t delta_size) { if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size) return 0; @@ -1982,14 +1982,15 @@ static pthread_mutex_t progress_mutex; * reconstruction (so non-deltas are true object sizes, but deltas * return the size of the delta data). */ -unsigned long oe_get_size_slow(struct packing_data *pack, +size_t oe_get_size_slow(struct packing_data *pack, const struct object_entry *e) { struct packed_git *p; struct pack_window *w_curs; unsigned char *buf; enum object_type type; - unsigned long used, avail, size; + size_t used, size; + size_t avail; if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) { packing_data_lock(&to_pack); @@ -2018,11 +2019,11 @@ unsigned long oe_get_size_slow(struct packing_data *pack, } static int try_delta(struct unpacked *trg, struct unpacked *src, - unsigned max_depth, unsigned long *mem_usage) + unsigned max_depth, size_t *mem_usage) { struct object_entry *trg_entry = trg->entry; struct object_entry *src_entry = src->entry; - unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz; + size_t trg_size, src_size, delta_size, sizediff, max_size, sz; unsigned ref_depth; enum object_type type; void *delta_buf; @@ -2178,9 +2179,9 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n) return m; } -static unsigned long free_unpacked(struct unpacked *n) +static size_t free_unpacked(struct unpacked *n) { - unsigned long freed_mem = sizeof_delta_index(n->index); + size_t freed_mem = sizeof_delta_index(n->index); free_delta_index(n->index); n->index = NULL; if (n->data) { @@ -2197,7 +2198,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size, { uint32_t i, idx = 0, count = 0; struct unpacked *array; - unsigned long mem_usage = 0; + size_t mem_usage = 0; array = xcalloc(window, sizeof(struct unpacked)); @@ -2280,7 +2281,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size, * between writes at that moment. */ if (entry->delta_data && !pack_to_stdout) { - unsigned long size; + size_t size; size = do_compress(&entry->delta_data, DELTA_SIZE(entry)); if (size < (1U << OE_Z_DELTA_BITS)) { diff --git a/builtin/reflog.c b/builtin/reflog.c index b35676b19c5af2..3f1a645b8d99a5 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -82,7 +82,7 @@ static int tree_is_complete(const struct object_id *oid) if (!tree->buffer) { enum object_type type; - unsigned long size; + size_t size; void *data = read_object_file(oid, &type, &size); if (!data) { tree->object.flags |= INCOMPLETE; diff --git a/builtin/replace.c b/builtin/replace.c index 644b21ca8d57a7..55409634032a54 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -446,7 +446,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle) struct commit *commit; struct strbuf buf = STRBUF_INIT; const char *buffer; - unsigned long size; + size_t size; if (get_oid(old_ref, &old_oid) < 0) return error(_("not a valid object name: '%s'"), old_ref); diff --git a/builtin/tag.c b/builtin/tag.c index ef37dccf864932..bdc9bfebc3260d 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -166,7 +166,7 @@ static int git_tag_config(const char *var, const char *value, void *cb) static void write_tag_body(int fd, const struct object_id *oid) { - unsigned long size; + size_t size; enum object_type type; char *buf, *sp; @@ -297,7 +297,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) enum object_type type; struct commit *c; char *buf; - unsigned long size; + size_t size; int subject_len = 0; const char *subject_start; diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 58652229f273bf..61200ed57ce06c 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -7,7 +7,7 @@ static char *create_temp_file(struct object_id *oid) static char path[50]; void *buf; enum object_type type; - unsigned long size; + size_t size; int fd; buf = read_object_file(oid, &type, &size); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 80478808b3dcc7..69bf9c8500ac9e 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -32,7 +32,7 @@ static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT; */ struct obj_buffer { char *buffer; - unsigned long size; + size_t size; }; static struct decoration obj_decorate; @@ -42,7 +42,7 @@ static struct obj_buffer *lookup_object_buffer(struct object *base) return lookup_decoration(&obj_decorate, base); } -static void add_object_buffer(struct object *object, char *buffer, unsigned long size) +static void add_object_buffer(struct object *object, char *buffer, size_t size) { struct obj_buffer *obj; obj = xcalloc(1, sizeof(struct obj_buffer)); @@ -94,7 +94,7 @@ static void use(int bytes) die(_("pack exceeds maximum allowed size")); } -static void *get_data(unsigned long size) +static void *get_data(size_t size) { git_zstream stream; void *buf = xmallocz(size); @@ -131,7 +131,7 @@ struct delta_info { struct object_id base_oid; unsigned nr; off_t base_offset; - unsigned long size; + size_t size; void *delta; struct delta_info *next; }; @@ -140,7 +140,7 @@ static struct delta_info *delta_list; static void add_delta_to_list(unsigned nr, const struct object_id *base_oid, off_t base_offset, - void *delta, unsigned long size) + void *delta, size_t size) { struct delta_info *info = xmalloc(sizeof(*info)); @@ -199,7 +199,7 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op die("object type mismatch"); if (!(obj->flags & FLAG_OPEN)) { - unsigned long size; + size_t size; int type = oid_object_info(the_repository, &obj->oid, &size); if (type != obj->type || type <= 0) die("object of unexpected type"); @@ -229,7 +229,7 @@ static void write_rest(void) } static void added_object(unsigned nr, enum object_type type, - void *data, unsigned long size); + void *data, size_t size); /* * Write out nr-th object from the list, now we know the contents @@ -237,7 +237,7 @@ static void added_object(unsigned nr, enum object_type type, * to be checked at the end. */ static void write_object(unsigned nr, enum object_type type, - void *buf, unsigned long size) + void *buf, size_t size) { if (!strict) { if (write_object_file(buf, size, type_name(type), @@ -277,11 +277,11 @@ static void write_object(unsigned nr, enum object_type type, } static void resolve_delta(unsigned nr, enum object_type type, - void *base, unsigned long base_size, - void *delta, unsigned long delta_size) + void *base, size_t base_size, + void *delta, size_t delta_size) { void *result; - unsigned long result_size; + size_t result_size; result = patch_delta(base, base_size, delta, delta_size, @@ -297,7 +297,7 @@ static void resolve_delta(unsigned nr, enum object_type type, * resolve all the deltified objects that are based on it. */ static void added_object(unsigned nr, enum object_type type, - void *data, unsigned long size) + void *data, size_t size) { struct delta_info **p = &delta_list; struct delta_info *info; @@ -316,7 +316,7 @@ static void added_object(unsigned nr, enum object_type type, } } -static void unpack_non_delta_entry(enum object_type type, unsigned long size, +static void unpack_non_delta_entry(enum object_type type, size_t size, unsigned nr) { void *buf = get_data(size); @@ -328,7 +328,7 @@ static void unpack_non_delta_entry(enum object_type type, unsigned long size, } static int resolve_against_held(unsigned nr, const struct object_id *base, - void *delta_data, unsigned long delta_size) + void *delta_data, size_t delta_size) { struct object *obj; struct obj_buffer *obj_buffer; @@ -343,11 +343,11 @@ static int resolve_against_held(unsigned nr, const struct object_id *base, return 1; } -static void unpack_delta_entry(enum object_type type, unsigned long delta_size, +static void unpack_delta_entry(enum object_type type, size_t delta_size, unsigned nr) { void *delta_data, *base; - unsigned long base_size; + size_t base_size; struct object_id base_oid; if (type == OBJ_REF_DELTA) { @@ -442,7 +442,7 @@ static void unpack_one(unsigned nr) { unsigned shift; unsigned char *pack; - unsigned long size, c; + size_t size, c; enum object_type type; obj_list[nr].offset = consumed_bytes; diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 7772c07ed7a1e1..0c25550ef1fd4b 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -21,7 +21,7 @@ static const char * const verify_commit_usage[] = { NULL }; -static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned long size, unsigned flags) +static int run_gpg_verify(const struct object_id *oid, const char *buf, size_t size, unsigned flags) { struct signature_check signature_check; int ret; @@ -41,7 +41,7 @@ static int verify_commit(const char *name, unsigned flags) enum object_type type; struct object_id oid; char *buf; - unsigned long size; + size_t size; int ret; if (get_oid(name, &oid)) diff --git a/bundle.c b/bundle.c index b45666c49b1c19..518763818f7cbc 100644 --- a/bundle.c +++ b/bundle.c @@ -217,7 +217,7 @@ int list_bundle_refs(struct bundle_header *header, int argc, const char **argv) static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) { - unsigned long size; + size_t size; enum object_type type; char *buf = NULL, *line, *lineend; timestamp_t date; diff --git a/cache.h b/cache.h index bf20337ef43523..019ea848a9524a 100644 --- a/cache.h +++ b/cache.h @@ -21,10 +21,10 @@ #include typedef struct git_zstream { z_stream z; - unsigned long avail_in; - unsigned long avail_out; - unsigned long total_in; - unsigned long total_out; + size_t avail_in; + size_t avail_out; + size_t total_in; + size_t total_out; unsigned char *next_in; unsigned char *next_out; } git_zstream; @@ -41,7 +41,7 @@ void git_deflate_end(git_zstream *); int git_deflate_abort(git_zstream *); int git_deflate_end_gently(git_zstream *); int git_deflate(git_zstream *, int flush); -unsigned long git_deflate_bound(git_zstream *, unsigned long); +size_t git_deflate_bound(git_zstream *, size_t); /* The length in bytes and in hex digits of an object name (SHA-1 value). */ #define GIT_SHA1_RAWSZ 20 @@ -785,7 +785,7 @@ int chmod_index_entry(struct index_state *, struct cache_entry *ce, char flip); int ce_same_name(const struct cache_entry *a, const struct cache_entry *b); void set_object_name_for_intent_to_add_entry(struct cache_entry *ce); int index_name_is_other(const struct index_state *, const char *, int); -void *read_blob_data_from_index(const struct index_state *, const char *, unsigned long *); +void *read_blob_data_from_index(const struct index_state *, const char *, size_t *); /* do stat comparison even if CE_VALID is true */ #define CE_MATCH_IGNORE_VALID 01 @@ -865,8 +865,8 @@ extern int pack_compression_level; extern size_t packed_git_window_size; extern size_t packed_git_limit; extern size_t delta_base_cache_limit; -extern unsigned long big_file_threshold; -extern unsigned long pack_size_limit_cfg; +extern size_t big_file_threshold; +extern size_t pack_size_limit_cfg; /* * Accessors for the core.sharedrepository config which lazy-load the value @@ -1302,10 +1302,11 @@ char *xdg_cache_home(const char *filename); int git_open_cloexec(const char *name, int flags); #define git_open(name) git_open_cloexec(name, O_RDONLY) -int unpack_loose_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz); -int parse_loose_header(const char *hdr, unsigned long *sizep); -int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type); +int unpack_loose_header(git_zstream *stream, unsigned char *map, size_t mapsize, void *buffer, size_t bufsiz); +int parse_loose_header(const char *hdr, size_t *sizep); + +int check_object_signature(const struct object_id *oid, void *buf, size_t size, const char *type); int finalize_object_file(const char *tmpfile, const char *filename); @@ -1501,9 +1502,9 @@ int name_compare(const char *name1, size_t len1, const char *name2, size_t len2) int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); void *read_object_with_reference(const struct object_id *oid, - const char *required_type, - unsigned long *size, - struct object_id *oid_ret); + const char *required_type, + size_t *size, + struct object_id *oid_ret); struct object *repo_peel_to_type(struct repository *r, const char *name, int namelen, @@ -1886,4 +1887,10 @@ int print_sha1_ellipsis(void); /* Return 1 if the file is empty or does not exists, 0 otherwise. */ int is_empty_or_missing_file(const char *filename); +/* + * Extended crc32 with 64 bit address range + * On Windows, uInt/uLong are only 32 bits. + */ +extern uLong xcrc32(uLong crc, const unsigned char *buf, size_t bytes); + #endif /* CACHE_H */ diff --git a/combine-diff.c b/combine-diff.c index 3e49f3bda84b92..5fe1e24faf39a8 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -311,7 +311,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase, static char *grab_blob(struct repository *r, const struct object_id *oid, unsigned int mode, - unsigned long *size, struct userdiff_driver *textconv, + size_t *size, struct userdiff_driver *textconv, const char *path) { char *blob; @@ -403,7 +403,7 @@ static void consume_hunk(void *state_, state->sline[state->nb-1].p_lno[state->n] = state->ob; } -static void consume_line(void *state_, char *line, unsigned long len) +static void consume_line(void *state_, char *line, size_t len) { struct combine_diff_state *state = state_; if (!state->lost_bucket) @@ -433,7 +433,7 @@ static void combine_diff(struct repository *r, xdemitconf_t xecfg; mmfile_t parent_file; struct combine_diff_state state; - unsigned long sz; + size_t sz; if (result_deleted) return; /* result deleted */ @@ -1016,7 +1016,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, struct rev_info *rev) { struct diff_options *opt = &rev->diffopt; - unsigned long result_size, cnt, lno; + unsigned long cnt, lno; + size_t result_size; int result_deleted = 0; char *result, *cp; struct sline *sline; /* survived lines */ @@ -1134,7 +1135,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, is_binary = buffer_is_binary(result, result_size); for (i = 0; !is_binary && i < num_parent; i++) { char *buf; - unsigned long size; + size_t size; buf = grab_blob(opt->repo, &elem->parent[i].oid, elem->parent[i].mode, diff --git a/commit.c b/commit.c index 8fa1883c61c580..772d5057b34e88 100644 --- a/commit.c +++ b/commit.c @@ -260,7 +260,7 @@ int unregister_shallow(const struct object_id *oid) struct commit_buffer { void *buffer; - unsigned long size; + size_t size; }; define_commit_slab(buffer_slab, struct commit_buffer); @@ -277,7 +277,7 @@ void free_commit_buffer_slab(struct buffer_slab *bs) free(bs); } -void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, unsigned long size) +void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer, size_t size) { struct commit_buffer *v = buffer_slab_at( r->parsed_objects->buffer_slab, commit); @@ -285,7 +285,7 @@ void set_commit_buffer(struct repository *r, struct commit *commit, void *buffer v->size = size; } -const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, unsigned long *sizep) +const void *get_cached_commit_buffer(struct repository *r, const struct commit *commit, size_t *sizep) { struct commit_buffer *v = buffer_slab_peek( r->parsed_objects->buffer_slab, commit); @@ -301,12 +301,12 @@ const void *get_cached_commit_buffer(struct repository *r, const struct commit * const void *repo_get_commit_buffer(struct repository *r, const struct commit *commit, - unsigned long *sizep) + size_t *sizep) { const void *ret = get_cached_commit_buffer(r, commit, sizep); if (!ret) { enum object_type type; - unsigned long size; + size_t size; ret = repo_read_object_file(r, &commit->object.oid, &type, &size); if (!ret) die("cannot read commit object %s", @@ -372,7 +372,7 @@ void release_commit_memory(struct parsed_object_pool *pool, struct commit *c) c->object.parsed = 0; } -const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) +const void *detach_commit_buffer(struct commit *commit, size_t *sizep) { struct commit_buffer *v = buffer_slab_peek( the_repository->parsed_objects->buffer_slab, commit); @@ -392,7 +392,7 @@ const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) return ret; } -int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph) +int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, size_t size, int check_graph) { const char *tail = buffer; const char *bufptr = buffer; @@ -461,7 +461,7 @@ int repo_parse_commit_internal(struct repository *r, { enum object_type type; void *buffer; - unsigned long size; + size_t size; int ret; if (!item) @@ -982,7 +982,7 @@ int parse_signed_commit(const struct commit *commit, struct strbuf *payload, struct strbuf *signature) { - unsigned long size; + size_t size; const char *buffer = get_commit_buffer(commit, &size); int in_signature, saw_signature = -1; const char *line, *tail; @@ -1057,7 +1057,7 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header struct merge_remote_desc *desc; struct commit_extra_header *mergetag; char *buf; - unsigned long size, len; + size_t size, len; enum object_type type; desc = merge_remote_util(parent); @@ -1164,7 +1164,7 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit, const char **exclude) { struct commit_extra_header *extra = NULL; - unsigned long size; + size_t size; const char *buffer = get_commit_buffer(commit, &size); extra = read_commit_extra_header_lines(buffer, size, exclude); unuse_commit_buffer(commit, buffer); diff --git a/commit.h b/commit.h index e9f96fefd7f9bf..8772e9bd90eb5b 100644 --- a/commit.h +++ b/commit.h @@ -79,7 +79,7 @@ struct commit *lookup_commit_reference_by_name(const char *name); */ struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name); -int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph); +int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, size_t size, int check_graph); int repo_parse_commit_internal(struct repository *r, struct commit *item, int quiet_on_missing, int use_commit_graph); int repo_parse_commit_gently(struct repository *r, @@ -111,13 +111,13 @@ void free_commit_buffer_slab(struct buffer_slab *bs); * Associate an object buffer with the commit. The ownership of the * memory is handed over to the commit, and must be free()-able. */ -void set_commit_buffer(struct repository *r, struct commit *, void *buffer, unsigned long size); +void set_commit_buffer(struct repository *r, struct commit *, void *buffer, size_t size); /* * Get any cached object buffer associated with the commit. Returns NULL * if none. The resulting memory should not be freed. */ -const void *get_cached_commit_buffer(struct repository *, const struct commit *, unsigned long *size); +const void *get_cached_commit_buffer(struct repository *, const struct commit *, size_t *size); /* * Get the commit's object contents, either from cache or by reading the object @@ -126,7 +126,7 @@ const void *get_cached_commit_buffer(struct repository *, const struct commit *, */ const void *repo_get_commit_buffer(struct repository *r, const struct commit *, - unsigned long *size); + size_t *size); #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS #define get_commit_buffer(c, s) repo_get_commit_buffer(the_repository, c, s) #endif @@ -163,7 +163,7 @@ void release_commit_memory(struct parsed_object_pool *pool, struct commit *c); * Disassociate any cached object buffer from the commit, but do not free it. * The buffer (or NULL, if none) is returned. */ -const void *detach_commit_buffer(struct commit *, unsigned long *sizep); +const void *detach_commit_buffer(struct commit *, size_t *sizep); /* Find beginning and length of commit subject. */ int find_commit_subject(const char *commit_buffer, const char **subject); diff --git a/config.c b/config.c index 22b68605680ab8..aad42ec18bbcaf 100644 --- a/config.c +++ b/config.c @@ -931,7 +931,16 @@ static int git_parse_int64(const char *value, int64_t *ret) int git_parse_ulong(const char *value, unsigned long *ret) { uintmax_t tmp; - if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(long))) + if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(unsigned long))) + return 0; + *ret = tmp; + return 1; +} + +int git_parse_size_t(const char *value, size_t *ret) +{ + uintmax_t tmp; + if (!git_parse_unsigned(value, &tmp, maximum_unsigned_value_of_type(size_t))) return 0; *ret = tmp; return 1; @@ -1004,6 +1013,15 @@ unsigned long git_config_ulong(const char *name, const char *value) return ret; } +/* on Windows we require size_t to cover the 64-bit range */ +size_t git_config_size_t(const char *name, const char *value) +{ + size_t ret; + if (!git_parse_size_t(value, &ret)) + die_bad_number(name, value); + return ret; +} + ssize_t git_config_ssize_t(const char *name, const char *value) { ssize_t ret; @@ -1218,12 +1236,12 @@ static int git_default_core_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "core.bigfilethreshold")) { - big_file_threshold = git_config_ulong(var, value); + big_file_threshold = git_config_size_t(var, value); return 0; } if (!strcmp(var, "core.packedgitlimit")) { - packed_git_limit = git_config_ulong(var, value); + packed_git_limit = git_config_size_t(var, value); return 0; } @@ -1471,7 +1489,7 @@ int git_default_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "pack.packsizelimit")) { - pack_size_limit_cfg = git_config_ulong(var, value); + pack_size_limit_cfg = git_config_size_t(var, value); return 0; } @@ -1596,7 +1614,7 @@ int git_config_from_blob_oid(config_fn_t fn, { enum object_type type; char *buf; - unsigned long size; + size_t size; int ret; buf = read_object_file(oid, &type, &size); @@ -1655,6 +1673,18 @@ unsigned long git_env_ulong(const char *k, unsigned long val) return val; } +/* + * Parse environment variable 'k' as ulong with possibly a unit + * suffix; if missing, use the default value 'val'. + */ +size_t git_env_size_t(const char *k, size_t val) +{ + const char *v = getenv(k); + if (v && !git_parse_size_t(v, &val)) + die(_("failed to parse %s"), k); + return val; +} + int git_config_system(void) { return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0); diff --git a/config.h b/config.h index f0ed464004da60..f3a64762259fad 100644 --- a/config.h +++ b/config.h @@ -94,10 +94,12 @@ int config_with_options(config_fn_t fn, void *, const struct config_options *opts); int git_parse_ssize_t(const char *, ssize_t *); int git_parse_ulong(const char *, unsigned long *); +int git_parse_size_t(const char *, size_t *); int git_parse_maybe_bool(const char *); int git_config_int(const char *, const char *); int64_t git_config_int64(const char *, const char *); unsigned long git_config_ulong(const char *, const char *); +size_t git_config_size_t(const char *, const char *); ssize_t git_config_ssize_t(const char *, const char *); int git_config_bool_or_int(const char *, const char *, int *); int git_config_bool(const char *, const char *); @@ -122,8 +124,10 @@ int git_config_copy_section_in_file(const char *, const char *, const char *); const char *git_etc_gitconfig(void); int git_env_bool(const char *, int); unsigned long git_env_ulong(const char *, unsigned long); +size_t git_env_size_t(const char *, size_t); int git_config_system(void); int config_error_nonbool(const char *); + #if defined(__GNUC__) #define config_error_nonbool(s) (config_error_nonbool(s), const_error()) #endif diff --git a/config.mak.uname b/config.mak.uname index 157a2441163972..3388b163839df2 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -424,6 +424,8 @@ ifeq ($(uname_S),Windows) NO_POSIX_GOODIES = UnfortunatelyYes NATIVE_CRLF = YesPlease DEFAULT_HELP_FORMAT = html + NO_DEFLATE_BOUND = YesPlease + # the zlib.c deflateBound, compiled for windows, is limited to uLong 32bit sourceLen. CC = compat/vcbuild/scripts/clink.pl AR = compat/vcbuild/scripts/lib.pl diff --git a/convert.c b/convert.c index 94ff8376492257..a8f94eec73e030 100644 --- a/convert.c +++ b/convert.c @@ -42,9 +42,9 @@ struct text_stat { unsigned printable, nonprintable; }; -static void gather_stats(const char *buf, unsigned long size, struct text_stat *stats) +static void gather_stats(const char *buf, size_t size, struct text_stat *stats) { - unsigned long i; + size_t i; memset(stats, 0, sizeof(*stats)); @@ -102,7 +102,7 @@ static int convert_is_binary(const struct text_stat *stats) return 0; } -static unsigned int gather_convert_stats(const char *data, unsigned long size) +static unsigned int gather_convert_stats(const char *data, size_t size) { struct text_stat stats; int ret = 0; @@ -119,7 +119,7 @@ static unsigned int gather_convert_stats(const char *data, unsigned long size) return ret; } -static const char *gather_convert_stats_ascii(const char *data, unsigned long size) +static const char *gather_convert_stats_ascii(const char *data, size_t size) { unsigned int convert_stats = gather_convert_stats(data, size); @@ -141,7 +141,7 @@ const char *get_cached_convert_stats_ascii(const struct index_state *istate, const char *path) { const char *ret; - unsigned long sz; + size_t sz; void *data = read_blob_data_from_index(istate, path, &sz); ret = gather_convert_stats_ascii(data, sz); free(data); @@ -223,7 +223,7 @@ static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_ static int has_crlf_in_index(const struct index_state *istate, const char *path) { - unsigned long sz; + size_t sz; void *data; const char *crp; int has_crlf = 0; @@ -629,7 +629,7 @@ static int crlf_to_worktree(const char *src, size_t len, struct filter_params { const char *src; - unsigned long size; + size_t size; int fd; const char *cmd; const char *path; @@ -1048,7 +1048,7 @@ static int read_convert_config(const char *var, const char *value, void *cb) return 0; } -static int count_ident(const char *cp, unsigned long size) +static int count_ident(const char *cp, size_t size) { /* * "$Id: 0000000000000000000000000000000000000000 $" <=> "$Id$" diff --git a/csum-file.c b/csum-file.c index 53ce37f7ca4299..216b29b9936bf3 100644 --- a/csum-file.c +++ b/csum-file.c @@ -11,7 +11,7 @@ #include "progress.h" #include "csum-file.h" -static void flush(struct hashfile *f, const void *buf, unsigned int count) +static void flush(struct hashfile *f, const void *buf, size_t count) { if (0 <= f->check_fd && count) { unsigned char check_buffer[8192]; @@ -22,7 +22,8 @@ static void flush(struct hashfile *f, const void *buf, unsigned int count) if (ret != count) die("%s: sha1 file truncated", f->name); if (memcmp(buf, check_buffer, count)) - die("sha1 file '%s' validation error", f->name); + die("sha1 file '%s' validation error, Count %"PRIuMAX, + f->name, (uintmax_t)count); } for (;;) { @@ -44,7 +45,7 @@ static void flush(struct hashfile *f, const void *buf, unsigned int count) void hashflush(struct hashfile *f) { - unsigned offset = f->offset; + size_t offset = f->offset; if (offset) { the_hash_algo->update_fn(&f->ctx, f->buffer, offset); @@ -86,16 +87,16 @@ int finalize_hashfile(struct hashfile *f, unsigned char *result, unsigned int fl return fd; } -void hashwrite(struct hashfile *f, const void *buf, unsigned int count) +void hashwrite(struct hashfile *f, const void *buf, size_t count) { while (count) { - unsigned offset = f->offset; - unsigned left = sizeof(f->buffer) - offset; - unsigned nr = count > left ? left : count; + size_t offset = f->offset; + size_t left = sizeof(f->buffer) - offset; + size_t nr = count > left ? left : count; const void *data; if (f->do_crc) - f->crc32 = crc32(f->crc32, buf, nr); + f->crc32 = xcrc32(f->crc32, buf, nr); if (nr == sizeof(f->buffer)) { /* process full buffer directly without copy */ diff --git a/csum-file.h b/csum-file.h index a98b1eee53f403..23f07faf49b661 100644 --- a/csum-file.h +++ b/csum-file.h @@ -9,7 +9,7 @@ struct progress; struct hashfile { int fd; int check_fd; - unsigned int offset; + size_t offset; git_hash_ctx ctx; off_t total; struct progress *tp; @@ -37,7 +37,7 @@ struct hashfile *hashfd(int fd, const char *name); struct hashfile *hashfd_check(const char *name); struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp); int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int); -void hashwrite(struct hashfile *, const void *, unsigned int); +void hashwrite(struct hashfile *, const void *, size_t); void hashflush(struct hashfile *f); void crc32_begin(struct hashfile *); uint32_t crc32_end(struct hashfile *); diff --git a/delta.h b/delta.h index 2df5fe13d954df..f7cca448f5b648 100644 --- a/delta.h +++ b/delta.h @@ -42,8 +42,8 @@ unsigned long sizeof_delta_index(struct delta_index *index); */ void * create_delta(const struct delta_index *index, - const void *buf, unsigned long bufsize, - unsigned long *delta_size, unsigned long max_delta_size); + const void *buf, size_t bufsize, + size_t *delta_size, size_t max_delta_size); /* * diff_delta: create a delta from source buffer to target buffer @@ -54,9 +54,9 @@ create_delta(const struct delta_index *index, * updated with its size. The returned buffer must be freed by the caller. */ static inline void * -diff_delta(const void *src_buf, unsigned long src_bufsize, - const void *trg_buf, unsigned long trg_bufsize, - unsigned long *delta_size, unsigned long max_delta_size) +diff_delta(const void *src_buf, size_t src_bufsize, + const void *trg_buf, size_t trg_bufsize, + size_t *delta_size, size_t max_delta_size) { struct delta_index *index = create_delta_index(src_buf, src_bufsize); if (index) { @@ -75,9 +75,9 @@ diff_delta(const void *src_buf, unsigned long src_bufsize, * *trg_bufsize is updated with its size. On failure a NULL pointer is * returned. The returned buffer must be freed by the caller. */ -void *patch_delta(const void *src_buf, unsigned long src_size, - const void *delta_buf, unsigned long delta_size, - unsigned long *dst_size); +void *patch_delta(const void *src_buf, size_t src_size, + const void *delta_buf, size_t delta_size, + size_t *dst_size); /* the smallest possible delta size is 4 bytes */ #define DELTA_SIZE_MIN 4 @@ -86,11 +86,11 @@ void *patch_delta(const void *src_buf, unsigned long src_size, * This must be called twice on the delta data buffer, first to get the * expected source buffer size, and again to get the target buffer size. */ -static inline unsigned long get_delta_hdr_size(const unsigned char **datap, +static inline size_t get_delta_hdr_size(const unsigned char **datap, const unsigned char *top) { const unsigned char *data = *datap; - unsigned long cmd, size = 0; + size_t cmd, size = 0; int i = 0; do { cmd = *data++; diff --git a/diff-delta.c b/diff-delta.c index e49643353bf568..072a5ca839d556 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -316,8 +316,8 @@ unsigned long sizeof_delta_index(struct delta_index *index) void * create_delta(const struct delta_index *index, - const void *trg_buf, unsigned long trg_size, - unsigned long *delta_size, unsigned long max_size) + const void *trg_buf, size_t trg_size, + size_t *delta_size, size_t max_size) { unsigned int i, val; off_t outpos, moff; diff --git a/diff.c b/diff.c index dd8e09ac5e9268..795edc94987f52 100644 --- a/diff.c +++ b/diff.c @@ -2323,7 +2323,7 @@ static void find_lno(const char *line, struct emit_callback *ecbdata) ecbdata->lno_in_postimage = strtol(p + 1, NULL, 10); } -static void fn_out_consume(void *priv, char *line, unsigned long len) +static void fn_out_consume(void *priv, char *line, size_t len) { struct emit_callback *ecbdata = priv; struct diff_options *o = ecbdata->opt; @@ -2509,7 +2509,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat, return x; } -static void diffstat_consume(void *priv, char *line, unsigned long len) +static void diffstat_consume(void *priv, char *line, size_t len) { struct diffstat_t *diffstat = priv; struct diffstat_file *x = diffstat->files[diffstat->nr - 1]; @@ -3189,7 +3189,7 @@ static void checkdiff_consume_hunk(void *priv, data->lineno = nb - 1; } -static void checkdiff_consume(void *priv, char *line, unsigned long len) +static void checkdiff_consume(void *priv, char *line, size_t len) { struct checkdiff_t *data = priv; int marker_size = data->conflict_marker_size; @@ -3228,8 +3228,8 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len) } static unsigned char *deflate_it(char *data, - unsigned long size, - unsigned long *result_size) + size_t size, + size_t *result_size) { int bound; unsigned char *deflated; @@ -3257,10 +3257,10 @@ static void emit_binary_diff_body(struct diff_options *o, void *delta; void *deflated; void *data; - unsigned long orig_size; - unsigned long delta_size; - unsigned long deflate_size; - unsigned long data_size; + size_t orig_size; + size_t delta_size; + size_t deflate_size; + size_t data_size; /* We could do deflated delta, or we could do just deflated two, * whichever is smaller. @@ -4048,7 +4048,7 @@ void diff_free_filespec_data(struct diff_filespec *s) static void prep_temp_blob(struct index_state *istate, const char *path, struct diff_tempfile *temp, void *blob, - unsigned long size, + size_t size, const struct object_id *oid, int mode) { @@ -5965,9 +5965,9 @@ struct patch_id_t { int patchlen; }; -static int remove_space(char *line, int len) +static size_t remove_space(char *line, size_t len) { - int i; + size_t i; char *dst = line; unsigned char c; @@ -5978,10 +5978,10 @@ static int remove_space(char *line, int len) return dst - line; } -static void patch_id_consume(void *priv, char *line, unsigned long len) +static void patch_id_consume(void *priv, char *line, size_t len) { struct patch_id_t *data = priv; - int new_len; + size_t new_len; new_len = remove_space(line, len); @@ -6786,7 +6786,7 @@ int textconv_object(struct repository *r, const struct object_id *oid, int oid_valid, char **buf, - unsigned long *buf_size) + size_t *buf_size) { struct diff_filespec *df; struct userdiff_driver *textconv; diff --git a/diff.h b/diff.h index be27553bd1f889..221564e8f231f0 100644 --- a/diff.h +++ b/diff.h @@ -499,7 +499,7 @@ int textconv_object(struct repository *repo, const char *path, unsigned mode, const struct object_id *oid, int oid_valid, - char **buf, unsigned long *buf_size); + char **buf, size_t *buf_size); int parse_rename_score(const char **cp_p); diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index a9c6d60df22862..7d15d4ecb966ed 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -19,7 +19,7 @@ struct diffgrep_cb { int hit; }; -static void diffgrep_consume(void *priv, char *line, unsigned long len) +static void diffgrep_consume(void *priv, char *line, size_t len) { struct diffgrep_cb *data = priv; regmatch_t regmatch; @@ -71,7 +71,7 @@ static int diff_grep(mmfile_t *one, mmfile_t *two, static unsigned int contains(mmfile_t *mf, regex_t *regexp, kwset_t kws) { unsigned int cnt; - unsigned long sz; + size_t sz; const char *data; sz = mf->size; diff --git a/diffcore.h b/diffcore.h index b651061c0e3a40..b47778dd36b487 100644 --- a/diffcore.h +++ b/diffcore.h @@ -33,7 +33,7 @@ struct diff_filespec { char *path; void *data; void *cnt_data; - unsigned long size; + size_t size; int count; /* Reference count */ int rename_used; /* Count of rename users */ unsigned short mode; /* file mode */ diff --git a/dir.c b/dir.c index 2832e5bca778ce..fe90388e411a8b 100644 --- a/dir.c +++ b/dir.c @@ -182,7 +182,7 @@ static size_t common_prefix_len(const struct pathspec *pathspec) */ char *common_prefix(const struct pathspec *pathspec) { - unsigned long len = common_prefix_len(pathspec); + size_t len = common_prefix_len(pathspec); return len ? xmemdupz(pathspec->items[0].match, len) : NULL; } @@ -238,7 +238,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat, size_t *size_out, char **data_out) { enum object_type type; - unsigned long sz; + size_t sz; char *data; *size_out = 0; @@ -2869,7 +2869,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data, oid_stat->valid = 1; } -struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz) +struct untracked_cache *read_untracked_extension(const void *data, size_t sz) { struct untracked_cache *uc; struct read_data rd; diff --git a/dir.h b/dir.h index 680079bbe3241f..09c119a4507620 100644 --- a/dir.h +++ b/dir.h @@ -362,7 +362,7 @@ void untracked_cache_remove_from_index(struct index_state *, const char *); void untracked_cache_add_to_index(struct index_state *, const char *); void free_untracked_cache(struct untracked_cache *); -struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz); +struct untracked_cache *read_untracked_extension(const void *data, size_t sz); void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked); void add_untracked_cache(struct index_state *istate); void remove_untracked_cache(struct index_state *istate); diff --git a/entry.c b/entry.c index b424b095d7cdb9..26acea6c666c7a 100644 --- a/entry.c +++ b/entry.c @@ -83,7 +83,7 @@ static int create_file(const char *path, unsigned int mode) return open(path, O_WRONLY | O_CREAT | O_EXCL, mode); } -static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size) +static void *read_blob_entry(const struct cache_entry *ce, size_t *size) { enum object_type type; void *blob_data = read_object_file(&ce->oid, &type, size); @@ -259,7 +259,7 @@ static int write_entry(struct cache_entry *ce, int fd, ret, fstat_done = 0; char *new_blob; struct strbuf buf = STRBUF_INIT; - unsigned long size; + size_t size; ssize_t wrote; size_t newsize = 0; struct stat st; diff --git a/environment.c b/environment.c index 89af47cb850490..b5071f058c6da6 100644 --- a/environment.c +++ b/environment.c @@ -47,7 +47,7 @@ int fsync_object_files; size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; size_t delta_base_cache_limit = 96 * 1024 * 1024; -unsigned long big_file_threshold = 512 * 1024 * 1024; +size_t big_file_threshold = 512 * 1024 * 1024; int pager_use_color = 1; const char *editor_program; const char *askpass_program; @@ -71,7 +71,7 @@ int grafts_replace_parents = 1; int core_apply_sparse_checkout; int merge_log_config = -1; int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ -unsigned long pack_size_limit_cfg; +size_t pack_size_limit_cfg; enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET; #ifndef PROTECT_HFS_DEFAULT diff --git a/fast-import.c b/fast-import.c index f38d04fa58510b..8c7100adbd938a 100644 --- a/fast-import.c +++ b/fast-import.c @@ -903,7 +903,7 @@ static int store_object( struct object_entry *e; unsigned char hdr[96]; struct object_id oid; - unsigned long hdrlen, deltalen; + size_t hdrlen, deltalen; git_hash_ctx c; git_zstream s; @@ -1045,7 +1045,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) unsigned char *out_buf = xmalloc(out_sz); struct object_entry *e; struct object_id oid; - unsigned long hdrlen; + size_t hdrlen; off_t offset; git_hash_ctx c; git_zstream s; @@ -1164,7 +1164,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) */ static void *gfi_unpack_entry( struct object_entry *oe, - unsigned long *sizep) + size_t *sizep) { enum object_type type; struct packed_git *p = all_packs[oe->pack_id]; @@ -1210,7 +1210,7 @@ static void load_tree(struct tree_entry *root) struct object_id *oid = &root->versions[1].oid; struct object_entry *myoe; struct tree_content *t; - unsigned long size; + size_t size; char *buf; const char *c; @@ -1873,7 +1873,7 @@ static int validate_raw_date(const char *src, struct strbuf *result) { const char *orig_src = src; char *endp; - unsigned long num; + size_t num; errno = 0; @@ -2409,7 +2409,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa die("Mark :%" PRIuMAX " not a commit", commit_mark); oidcpy(&commit_oid, &commit_oe->idx.oid); } else if (!get_oid(p, &commit_oid)) { - unsigned long size; + size_t size; char *buf = read_object_with_reference(&commit_oid, commit_type, &size, &commit_oid); @@ -2462,7 +2462,7 @@ static void file_change_deleteall(struct branch *b) b->num_notes = 0; } -static void parse_from_commit(struct branch *b, char *buf, unsigned long size) +static void parse_from_commit(struct branch *b, char *buf, size_t size) { if (!buf || size < the_hash_algo->hexsz + 6) die("Not a valid commit: %s", oid_to_hex(&b->oid)); @@ -2479,7 +2479,7 @@ static void parse_from_existing(struct branch *b) oidclr(&b->branch_tree.versions[0].oid); oidclr(&b->branch_tree.versions[1].oid); } else { - unsigned long size; + size_t size; char *buf; buf = read_object_with_reference(&b->oid, commit_type, &size, @@ -2516,7 +2516,7 @@ static int parse_from(struct branch *b) if (!oideq(&b->oid, &oe->idx.oid)) { oidcpy(&b->oid, &oe->idx.oid); if (oe->pack_id != MAX_PACK_ID) { - unsigned long size; + size_t size; char *buf = gfi_unpack_entry(oe, &size); parse_from_commit(b, buf, size); free(buf); @@ -2559,7 +2559,7 @@ static struct hash_list *parse_merge(unsigned int *count) die("Mark :%" PRIuMAX " not a commit", idnum); oidcpy(&n->oid, &oe->idx.oid); } else if (!get_oid(from, &n->oid)) { - unsigned long size; + size_t size; char *buf = read_object_with_reference(&n->oid, commit_type, &size, &n->oid); @@ -2787,7 +2787,7 @@ static void parse_reset_branch(const char *arg) unread_command_buf = 1; } -static void cat_blob_write(const char *buf, unsigned long size) +static void cat_blob_write(const char *buf, size_t size) { if (write_in_full(cat_blob_fd, buf, size) < 0) die_errno("Write to frontend failed"); @@ -2796,7 +2796,7 @@ static void cat_blob_write(const char *buf, unsigned long size) static void cat_blob(struct object_entry *oe, struct object_id *oid) { struct strbuf line = STRBUF_INIT; - unsigned long size; + size_t size; enum object_type type = 0; char *buf; @@ -2880,7 +2880,7 @@ static void parse_cat_blob(const char *p) static struct object_entry *dereference(struct object_entry *oe, struct object_id *oid) { - unsigned long size; + size_t size; char *buf = NULL; const unsigned hexsz = the_hash_algo->hexsz; diff --git a/fsck.c b/fsck.c index 4703f55561452c..f54d5bd5a7e524 100644 --- a/fsck.c +++ b/fsck.c @@ -850,7 +850,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer, } static int fsck_commit(struct commit *commit, const char *data, - unsigned long size, struct fsck_options *options) + size_t size, struct fsck_options *options) { const char *buffer = data ? data : get_commit_buffer(commit, &size); int ret = fsck_commit_buffer(commit, buffer, size, options); @@ -860,7 +860,7 @@ static int fsck_commit(struct commit *commit, const char *data, } static int fsck_tag_buffer(struct tag *tag, const char *data, - unsigned long size, struct fsck_options *options) + size_t size, struct fsck_options *options) { struct object_id oid; int ret = 0; @@ -955,7 +955,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data, } static int fsck_tag(struct tag *tag, const char *data, - unsigned long size, struct fsck_options *options) + size_t size, struct fsck_options *options) { struct object *tagged = tag->tagged; @@ -1006,7 +1006,7 @@ static int fsck_gitmodules_fn(const char *var, const char *value, void *vdata) } static int fsck_blob(struct blob *blob, const char *buf, - unsigned long size, struct fsck_options *options) + size_t size, struct fsck_options *options) { struct fsck_gitmodules_data data; struct config_options config_opts = { 0 }; @@ -1042,7 +1042,7 @@ static int fsck_blob(struct blob *blob, const char *buf, return data.ret; } -int fsck_object(struct object *obj, void *data, unsigned long size, +int fsck_object(struct object *obj, void *data, size_t size, struct fsck_options *options) { if (!obj) @@ -1084,7 +1084,7 @@ int fsck_finish(struct fsck_options *options) while ((oid = oidset_iter_next(&iter))) { struct blob *blob; enum object_type type; - unsigned long size; + size_t size; char *buf; if (oidset_contains(&gitmodules_done, oid)) diff --git a/fsck.h b/fsck.h index b95595ae5fee6c..939ccf856b1373 100644 --- a/fsck.h +++ b/fsck.h @@ -53,7 +53,7 @@ struct fsck_options { */ int fsck_walk(struct object *obj, void *data, struct fsck_options *options); /* If NULL is passed for data, we assume the object is local and read it. */ -int fsck_object(struct object *obj, void *data, unsigned long size, +int fsck_object(struct object *obj, void *data, size_t size, struct fsck_options *options); /* diff --git a/fuzz-pack-headers.c b/fuzz-pack-headers.c index 99da1d0fd385eb..d04e264e23d83a 100644 --- a/fuzz-pack-headers.c +++ b/fuzz-pack-headers.c @@ -5,10 +5,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { enum object_type type; - unsigned long len; + size_t len; unpack_object_header_buffer((const unsigned char *)data, - (unsigned long)size, &type, &len); + size, &type, &len); return 0; } diff --git a/grep.h b/grep.h index 1875880f37990f..b7933b2eadfd75 100644 --- a/grep.h +++ b/grep.h @@ -209,7 +209,7 @@ struct grep_source { void *identifier; char *buf; - unsigned long size; + size_t size; char *path; /* for attribute lookups */ struct userdiff_driver *driver; diff --git a/http-push.c b/http-push.c index e36561a6db0752..e1f200d8b7e136 100644 --- a/http-push.c +++ b/http-push.c @@ -360,7 +360,7 @@ static void start_put(struct transfer_request *request) enum object_type type; char hdr[50]; void *unpacked; - unsigned long len; + size_t len; int hdrlen; ssize_t size; git_zstream stream; @@ -370,7 +370,7 @@ static void start_put(struct transfer_request *request) /* Set it up */ git_deflate_init(&stream, zlib_compression_level); - size = git_deflate_bound(&stream, len + hdrlen); + size = git_deflate_bound(&stream, len + (size_t) hdrlen); strbuf_init(&request->buffer.buf, size); request->buffer.posn = 0; diff --git a/list-objects-filter.c b/list-objects-filter.c index 53f90442c5da99..9e2c0b37e29ccc 100644 --- a/list-objects-filter.c +++ b/list-objects-filter.c @@ -236,7 +236,7 @@ static enum list_objects_filter_result filter_blobs_limit( void *filter_data_) { struct filter_blobs_limit_data *filter_data = filter_data_; - unsigned long object_length; + size_t object_length; enum object_type t; switch (filter_situation) { diff --git a/mailmap.c b/mailmap.c index 962fd86d6d7067..ec7ba47eef654f 100644 --- a/mailmap.c +++ b/mailmap.c @@ -217,7 +217,7 @@ static int read_mailmap_blob(struct string_list *map, { struct object_id oid; char *buf; - unsigned long size; + size_t size; enum object_type type; if (!name) diff --git a/match-trees.c b/match-trees.c index 9d1ec8d6b01e13..ba10584c1f86bc 100644 --- a/match-trees.c +++ b/match-trees.c @@ -53,7 +53,7 @@ static void *fill_tree_desc_strict(struct tree_desc *desc, { void *buffer; enum object_type type; - unsigned long size; + size_t size; buffer = read_object_file(hash, &type, &size); if (!buffer) @@ -175,7 +175,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix, char *subpath; int toplen; char *buf; - unsigned long sz; + size_t sz; struct tree_desc desc; unsigned char *rewrite_here; const struct object_id *rewrite_with; diff --git a/merge-blobs.c b/merge-blobs.c index ee0a0e90c94682..f19ee015ccac07 100644 --- a/merge-blobs.c +++ b/merge-blobs.c @@ -9,7 +9,7 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj) { void *buf; - unsigned long size; + size_t size; enum object_type type; buf = read_object_file(&obj->object.oid, &type, &size); @@ -34,7 +34,7 @@ static void *three_way_filemerge(struct index_state *istate, mmfile_t *base, mmfile_t *our, mmfile_t *their, - unsigned long *size) + size_t *size) { int merge_status; mmbuffer_t res; @@ -57,7 +57,7 @@ static void *three_way_filemerge(struct index_state *istate, void *merge_blobs(struct index_state *istate, const char *path, struct blob *base, struct blob *our, - struct blob *their, unsigned long *size) + struct blob *their, size_t *size) { void *res = NULL; mmfile_t f1, f2, common; diff --git a/merge-blobs.h b/merge-blobs.h index 13cf9669e5b2c4..b0393f212fdfe5 100644 --- a/merge-blobs.h +++ b/merge-blobs.h @@ -5,7 +5,7 @@ struct blob; struct index_state; void *merge_blobs(struct index_state *, const char *, - struct blob *, struct blob *, - struct blob *, unsigned long *); + struct blob *, struct blob *, + struct blob *, size_t *); #endif /* MERGE_BLOBS_H */ diff --git a/merge-recursive.c b/merge-recursive.c index 6cdc64213bf2c7..d14f789afe2bd5 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -919,7 +919,7 @@ static int update_file_flags(struct merge_options *opt, if (update_wd) { enum object_type type; void *buf; - unsigned long size; + size_t size; if (S_ISGITLINK(contents->mode)) { /* @@ -2923,7 +2923,7 @@ static int read_oid_strbuf(struct merge_options *opt, { void *buf; enum object_type type; - unsigned long size; + size_t size; buf = read_object_file(oid, &type, &size); if (!buf) return err(opt, _("cannot read object %s"), oid_to_hex(oid)); diff --git a/notes-cache.c b/notes-cache.c index 2473314d686858..7914f1073fcc33 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -76,7 +76,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid, const struct object_id *value_oid; enum object_type type; char *value; - unsigned long size; + size_t size; value_oid = get_note(&c->tree, key_oid); if (!value_oid) diff --git a/notes-merge.c b/notes-merge.c index 2fe724f1cf8dc3..bfbb7258213787 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -297,7 +297,7 @@ static void check_notes_merge_worktree(struct notes_merge_options *o) } static void write_buf_to_worktree(const struct object_id *obj, - const char *buf, unsigned long size) + const char *buf, size_t size) { int fd; char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj)); @@ -326,7 +326,7 @@ static void write_note_to_worktree(const struct object_id *obj, const struct object_id *note) { enum object_type type; - unsigned long size; + size_t size; void *buf = read_object_file(note, &type, &size); if (!buf) diff --git a/notes.c b/notes.c index 532ec37865768d..c0c696e422a56c 100644 --- a/notes.c +++ b/notes.c @@ -793,7 +793,7 @@ int combine_notes_concatenate(struct object_id *cur_oid, const struct object_id *new_oid) { char *cur_msg = NULL, *new_msg = NULL, *buf; - unsigned long cur_len, new_len, buf_len; + size_t cur_len, new_len, buf_len; enum object_type cur_type, new_type; int ret; @@ -854,7 +854,7 @@ static int string_list_add_note_lines(struct string_list *list, const struct object_id *oid) { char *data; - unsigned long len; + size_t len; enum object_type t; if (is_null_oid(oid)) @@ -1208,7 +1208,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid static const char utf8[] = "utf-8"; const struct object_id *oid; char *msg, *msg_p; - unsigned long linelen, msglen; + size_t linelen, msglen; enum object_type type; if (!t) diff --git a/object-store.h b/object-store.h index 49f56ab8d96089..8d1011dab6266c 100644 --- a/object-store.h +++ b/object-store.h @@ -134,7 +134,7 @@ struct raw_object_store { * These two fields are not meant for direct access. Use * approximate_object_count() instead. */ - unsigned long approximate_object_count; + size_t approximate_object_count; unsigned approximate_object_count_valid : 1; /* @@ -155,16 +155,17 @@ const char *loose_object_path(struct repository *r, struct strbuf *buf, const struct object_id *oid); void *map_loose_object(struct repository *r, const struct object_id *oid, - unsigned long *size); + size_t *size); void *read_object_file_extended(struct repository *r, const struct object_id *oid, enum object_type *type, - unsigned long *size, int lookup_replace); + size_t *size, int lookup_replace); + static inline void *repo_read_object_file(struct repository *r, const struct object_id *oid, enum object_type *type, - unsigned long *size) + size_t *size) { return read_object_file_extended(r, oid, type, size, 1); } @@ -173,19 +174,19 @@ static inline void *repo_read_object_file(struct repository *r, #endif /* Read and unpack an object file into memory, write memory to an object file */ -int oid_object_info(struct repository *r, const struct object_id *, unsigned long *); +int oid_object_info(struct repository *r, const struct object_id *, size_t *); -int hash_object_file(const void *buf, unsigned long len, - const char *type, struct object_id *oid); +int hash_object_file(const void *buf, size_t len, + const char *type, struct object_id *oid); -int write_object_file(const void *buf, unsigned long len, - const char *type, struct object_id *oid); +int write_object_file(const void *buf, size_t len, + const char *type, struct object_id *oid); -int hash_object_file_literally(const void *buf, unsigned long len, - const char *type, struct object_id *oid, - unsigned flags); +int hash_object_file_literally(const void *buf, size_t len, + const char *type, struct object_id *oid, + unsigned flags); -int pretend_object_file(void *, unsigned long, enum object_type, +int pretend_object_file(void *, size_t, enum object_type, struct object_id *oid); int force_object_loose(const struct object_id *oid, time_t mtime); @@ -200,7 +201,7 @@ int force_object_loose(const struct object_id *oid, time_t mtime); int read_loose_object(const char *path, const struct object_id *expected_oid, enum object_type *type, - unsigned long *size, + size_t *size, void **contents); #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS @@ -229,7 +230,7 @@ void assert_oid_type(const struct object_id *oid, enum object_type expect); struct object_info { /* Request */ enum object_type *typep; - unsigned long *sizep; + size_t *sizep; off_t *disk_sizep; unsigned char *delta_base_sha1; struct strbuf *type_name; diff --git a/object.c b/object.c index cf1a2b708612a0..cb5122ca0b54fd 100644 --- a/object.c +++ b/object.c @@ -187,7 +187,7 @@ struct object *lookup_unknown_object(const unsigned char *sha1) return obj; } -struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) +struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, size_t size, void *buffer, int *eaten_p) { struct object *obj; *eaten_p = 0; @@ -249,7 +249,7 @@ struct object *parse_object_or_die(const struct object_id *oid, struct object *parse_object(struct repository *r, const struct object_id *oid) { - unsigned long size; + size_t size; enum object_type type; int eaten; const struct object_id *repl = lookup_replace_object(r, oid); diff --git a/object.h b/object.h index 4526979ccf264d..f104525fc5064a 100644 --- a/object.h +++ b/object.h @@ -140,7 +140,7 @@ struct object *parse_object_or_die(const struct object_id *oid, const char *name * parsing it. eaten_p indicates if the object has a borrowed copy * of buffer and the caller should not free() it. */ -struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p); +struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, size_t size, void *buffer, int *eaten_p); /** Returns the object, with potentially excess memory allocated. **/ struct object *lookup_unknown_object(const unsigned char *sha1); diff --git a/pack-check.c b/pack-check.c index 2cc3603189b8cd..ed3c240190e2df 100644 --- a/pack-check.c +++ b/pack-check.c @@ -33,11 +33,11 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, uint32_t data_crc = crc32(0, NULL, 0); do { - unsigned long avail; + size_t avail; void *data = use_pack(p, w_curs, offset, &avail); if (avail > len) avail = len; - data_crc = crc32(data_crc, data, avail); + data_crc = xcrc32(data_crc, data, avail); offset += avail; len -= avail; } while (len); @@ -69,7 +69,7 @@ static int verify_packfile(struct repository *r, the_hash_algo->init_fn(&ctx); do { - unsigned long remaining; + size_t remaining; unsigned char *in = use_pack(p, w_curs, offset, &remaining); offset += remaining; if (!pack_sig_ofs) @@ -108,7 +108,7 @@ static int verify_packfile(struct repository *r, for (i = 0; i < nr_objects; i++) { void *data; enum object_type type; - unsigned long size; + size_t size; off_t curpos; int data_valid; diff --git a/pack-objects.h b/pack-objects.h index 6fde7ce27cbc15..e4843efa35bc93 100644 --- a/pack-objects.h +++ b/pack-objects.h @@ -325,9 +325,9 @@ static inline void oe_set_delta_sibling(struct packing_data *pack, e->delta_sibling_idx = 0; } -unsigned long oe_get_size_slow(struct packing_data *pack, +size_t oe_get_size_slow(struct packing_data *pack, const struct object_entry *e); -static inline unsigned long oe_size(struct packing_data *pack, +static inline size_t oe_size(struct packing_data *pack, const struct object_entry *e) { if (e->size_valid) @@ -338,7 +338,7 @@ static inline unsigned long oe_size(struct packing_data *pack, static inline int oe_size_less_than(struct packing_data *pack, const struct object_entry *lhs, - unsigned long rhs) + size_t rhs) { if (lhs->size_valid) return lhs->size_ < rhs; @@ -349,7 +349,7 @@ static inline int oe_size_less_than(struct packing_data *pack, static inline int oe_size_greater_than(struct packing_data *pack, const struct object_entry *lhs, - unsigned long rhs) + size_t rhs) { if (lhs->size_valid) return lhs->size_ > rhs; @@ -360,7 +360,7 @@ static inline int oe_size_greater_than(struct packing_data *pack, static inline void oe_set_size(struct packing_data *pack, struct object_entry *e, - unsigned long size) + size_t size) { if (size < pack->oe_size_limit) { e->size_ = size; @@ -372,7 +372,7 @@ static inline void oe_set_size(struct packing_data *pack, } } -static inline unsigned long oe_delta_size(struct packing_data *pack, +static inline size_t oe_delta_size(struct packing_data *pack, const struct object_entry *e) { if (e->delta_size_valid) @@ -391,7 +391,7 @@ static inline unsigned long oe_delta_size(struct packing_data *pack, static inline void oe_set_delta_size(struct packing_data *pack, struct object_entry *e, - unsigned long size) + size_t size) { if (size < pack->oe_delta_size_limit) { e->delta_size_ = size; diff --git a/pack.h b/pack.h index 9fc0945ac9162e..6a45e1792a9bc4 100644 --- a/pack.h +++ b/pack.h @@ -77,7 +77,7 @@ struct pack_idx_entry { struct progress; /* Note, the data argument could be NULL if object type is blob */ -typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*); +typedef int (*verify_fn)(const struct object_id *, enum object_type, size_t, void*, int*); const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1); int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr); diff --git a/packfile.c b/packfile.c index e65752174dda7f..c96192c1bc639c 100644 --- a/packfile.c +++ b/packfile.c @@ -164,8 +164,8 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map, * variable sized table containing 8-byte entries * for offsets larger than 2^31. */ - unsigned long min_size = 8 + 4*256 + nr*(hashsz + 4 + 4) + hashsz + hashsz; - unsigned long max_size = min_size; + size_t min_size = 8 + 4*256 + nr*(hashsz + 4 + 4) + hashsz + hashsz; + size_t max_size = min_size; if (nr) max_size += (nr - 1)*8; if (idx_size < min_size || idx_size > max_size) @@ -603,7 +603,7 @@ static int in_window(struct pack_window *win, off_t offset) unsigned char *use_pack(struct packed_git *p, struct pack_window **w_cursor, off_t offset, - unsigned long *left) + size_t *left) { struct pack_window *win = *w_cursor; @@ -906,10 +906,10 @@ static void prepare_packed_git(struct repository *r); * all unreachable objects about to be pruned, in which case they're not really * interesting as a measure of repo size in the first place. */ -unsigned long repo_approximate_object_count(struct repository *r) +size_t repo_approximate_object_count(struct repository *r) { if (!r->objects->approximate_object_count_valid) { - unsigned long count; + size_t count; struct multi_pack_index *m; struct packed_git *p; @@ -1045,19 +1045,19 @@ struct list_head *get_packed_git_mru(struct repository *r) return &r->objects->packed_git_mru; } -unsigned long unpack_object_header_buffer(const unsigned char *buf, - unsigned long len, enum object_type *type, unsigned long *sizep) +size_t unpack_object_header_buffer(const unsigned char *buf, + size_t len, enum object_type *type, size_t *sizep) { unsigned shift; - unsigned long size, c; - unsigned long used = 0; + size_t size, c; + size_t used = 0; c = buf[used++]; *type = (c >> 4) & 7; size = c & 15; shift = 4; while (c & 0x80) { - if (len <= used || bitsizeof(long) <= shift) { + if (len <= used || bitsizeof(size_t) <= shift) { error("bad object header"); size = used = 0; break; @@ -1070,7 +1070,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, return used; } -unsigned long get_size_from_delta(struct packed_git *p, +size_t get_size_from_delta(struct packed_git *p, struct pack_window **w_curs, off_t curpos) { @@ -1112,11 +1112,11 @@ unsigned long get_size_from_delta(struct packed_git *p, int unpack_object_header(struct packed_git *p, struct pack_window **w_curs, off_t *curpos, - unsigned long *sizep) + size_t *sizep) { unsigned char *base; - unsigned long left; - unsigned long used; + size_t left; + size_t used; enum object_type type; /* use_pack() assures us we have [base, base + 20) available @@ -1267,7 +1267,7 @@ static enum object_type packed_to_object_type(struct repository *r, while (type == OBJ_OFS_DELTA || type == OBJ_REF_DELTA) { off_t base_offset; - unsigned long size; + size_t size; /* Push the object we're going to leave behind */ if (poi_stack_nr >= poi_stack_alloc && poi_stack == small_poi_stack) { poi_stack_alloc = alloc_nr(poi_stack_nr); @@ -1337,7 +1337,7 @@ struct delta_base_cache_entry { struct delta_base_cache_key key; struct list_head lru; void *data; - unsigned long size; + size_t size; enum object_type type; }; @@ -1402,7 +1402,7 @@ static void detach_delta_base_cache_entry(struct delta_base_cache_entry *ent) } static void *cache_or_unpack_entry(struct repository *r, struct packed_git *p, - off_t base_offset, unsigned long *base_size, + off_t base_offset, size_t *base_size, enum object_type *type) { struct delta_base_cache_entry *ent; @@ -1435,7 +1435,7 @@ void clear_delta_base_cache(void) } static void add_delta_base_cache(struct packed_git *p, off_t base_offset, - void *base, unsigned long base_size, enum object_type type) + void *base, size_t base_size, enum object_type type) { struct delta_base_cache_entry *ent = xmalloc(sizeof(*ent)); struct list_head *lru, *tmp; @@ -1467,7 +1467,7 @@ int packed_object_info(struct repository *r, struct packed_git *p, off_t obj_offset, struct object_info *oi) { struct pack_window *w_curs = NULL; - unsigned long size; + size_t size; off_t curpos = obj_offset; enum object_type type; @@ -1552,7 +1552,7 @@ int packed_object_info(struct repository *r, struct packed_git *p, static void *unpack_compressed_entry(struct packed_git *p, struct pack_window **w_curs, off_t curpos, - unsigned long size) + size_t size) { int st; git_zstream stream; @@ -1599,13 +1599,13 @@ int do_check_packed_object_crc; struct unpack_entry_stack_ent { off_t obj_offset; off_t curpos; - unsigned long size; + size_t size; }; static void *read_object(struct repository *r, const struct object_id *oid, enum object_type *type, - unsigned long *size) + size_t *size) { struct object_info oi = OBJECT_INFO_INIT; void *content; @@ -1619,12 +1619,12 @@ static void *read_object(struct repository *r, } void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, - enum object_type *final_type, unsigned long *final_size) + enum object_type *final_type, size_t *final_size) { struct pack_window *w_curs = NULL; off_t curpos = obj_offset; void *data = NULL; - unsigned long size; + size_t size; enum object_type type; struct unpack_entry_stack_ent small_delta_stack[UNPACK_ENTRY_STACK_PREALLOC]; struct unpack_entry_stack_ent *delta_stack = small_delta_stack; @@ -1724,7 +1724,7 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset, void *delta_data; void *base = data; void *external_base = NULL; - unsigned long delta_size, base_size = size; + size_t delta_size, base_size = size; int i; data = NULL; diff --git a/packfile.h b/packfile.h index 81e868d55a9b1f..b7bb014b52ae55 100644 --- a/packfile.h +++ b/packfile.h @@ -63,7 +63,7 @@ struct packed_git *get_all_packs(struct repository *r); * Give a rough count of objects in the repository. This sacrifices accuracy * for speed. */ -unsigned long repo_approximate_object_count(struct repository *r); +size_t repo_approximate_object_count(struct repository *r); #define approximate_object_count() repo_approximate_object_count(the_repository) struct packed_git *find_sha1_pack(const unsigned char *sha1, @@ -87,7 +87,7 @@ int close_pack_fd(struct packed_git *p); uint32_t get_pack_fanout(struct packed_git *p, uint32_t value); -unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *); +unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, size_t *); void close_pack_windows(struct packed_git *); void close_pack(struct packed_git *); void close_object_store(struct raw_object_store *o); @@ -140,10 +140,10 @@ off_t nth_packed_object_offset(const struct packed_git *, uint32_t n); off_t find_pack_entry_one(const unsigned char *sha1, struct packed_git *); int is_pack_valid(struct packed_git *); -void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *); -unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep); -unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t); -int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, unsigned long *); +void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, size_t *); +size_t unpack_object_header_buffer(const unsigned char *buf, size_t len, enum object_type *type, size_t *sizep); +size_t get_size_from_delta(struct packed_git *, struct pack_window **, off_t); +int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, size_t *); void release_pack_memory(size_t); diff --git a/patch-delta.c b/patch-delta.c index b5c8594db60dd1..42199fa95625d8 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -12,13 +12,13 @@ #include "git-compat-util.h" #include "delta.h" -void *patch_delta(const void *src_buf, unsigned long src_size, - const void *delta_buf, unsigned long delta_size, - unsigned long *dst_size) +void *patch_delta(const void *src_buf, size_t src_size, + const void *delta_buf, size_t delta_size, + size_t *dst_size) { const unsigned char *data, *top; unsigned char *dst_buf, *out, cmd; - unsigned long size; + size_t size; if (delta_size < DELTA_SIZE_MIN) return NULL; diff --git a/range-diff.c b/range-diff.c index 48b0e1b4ce0ff6..a70499089e410a 100644 --- a/range-diff.c +++ b/range-diff.c @@ -192,7 +192,7 @@ static void find_exact_matches(struct string_list *a, struct string_list *b) hashmap_free(&map, 0); } -static void diffsize_consume(void *data, char *line, unsigned long len) +static void diffsize_consume(void *data, char *line, size_t len) { (*(int *)data)++; } diff --git a/read-cache.c b/read-cache.c index bff65e022a3b29..5afe83e0eb6fc6 100644 --- a/read-cache.c +++ b/read-cache.c @@ -228,7 +228,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size) { int match = -1; void *buffer; - unsigned long size; + size_t size; enum object_type type; struct strbuf sb = STRBUF_INIT; @@ -1671,7 +1671,7 @@ int verify_index_checksum; /* Allow fsck to force verification of the cache entry order. */ int verify_ce_order; -static int verify_hdr(const struct cache_header *hdr, unsigned long size) +static int verify_hdr(const struct cache_header *hdr, size_t size) { git_hash_ctx c; unsigned char hash[GIT_MAX_RAWSZ]; @@ -1695,7 +1695,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size) } static int read_index_extension(struct index_state *istate, - const char *ext, const char *data, unsigned long sz) + const char *ext, const char *data, size_t sz) { switch (CACHE_EXT(ext)) { case CACHE_EXT_TREE: @@ -1731,7 +1731,7 @@ static int read_index_extension(struct index_state *istate, static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool, unsigned int version, struct ondisk_cache_entry *ondisk, - unsigned long *ent_size, + size_t *ent_size, const struct cache_entry *previous_ce) { struct cache_entry *ce; @@ -1924,13 +1924,13 @@ struct load_index_extensions struct index_state *istate; const char *mmap; size_t mmap_size; - unsigned long src_offset; + size_t src_offset; }; static void *load_index_extensions(void *_data) { struct load_index_extensions *p = _data; - unsigned long src_offset = p->src_offset; + size_t src_offset = p->src_offset; while (src_offset <= p->mmap_size - the_hash_algo->rawsz - 8) { /* After an array of active_nr index entries, @@ -1958,17 +1958,17 @@ static void *load_index_extensions(void *_data) * A helper function that will load the specified range of cache entries * from the memory mapped file and add them to the given index. */ -static unsigned long load_cache_entry_block(struct index_state *istate, +static size_t load_cache_entry_block(struct index_state *istate, struct mem_pool *ce_mem_pool, int offset, int nr, const char *mmap, - unsigned long start_offset, const struct cache_entry *previous_ce) + size_t start_offset, const struct cache_entry *previous_ce) { int i; - unsigned long src_offset = start_offset; + size_t src_offset = start_offset; for (i = offset; i < offset + nr; i++) { struct ondisk_cache_entry *disk_ce; struct cache_entry *ce; - unsigned long consumed; + size_t consumed; disk_ce = (struct ondisk_cache_entry *)(mmap + src_offset); ce = create_from_disk(ce_mem_pool, istate->version, disk_ce, &consumed, previous_ce); @@ -1980,10 +1980,10 @@ static unsigned long load_cache_entry_block(struct index_state *istate, return src_offset - start_offset; } -static unsigned long load_all_cache_entries(struct index_state *istate, - const char *mmap, size_t mmap_size, unsigned long src_offset) +static size_t load_all_cache_entries(struct index_state *istate, + const char *mmap, size_t mmap_size, size_t src_offset) { - unsigned long consumed; + size_t consumed; if (istate->version == 4) { mem_pool_init(&istate->ce_mem_pool, @@ -2017,7 +2017,7 @@ struct load_cache_entries_thread_data struct index_entry_offset_table *ieot; int ieot_start; /* starting index into the ieot array */ int ieot_blocks; /* count of ieot entries to process */ - unsigned long consumed; /* return # of bytes in index file processed */ + size_t consumed; /* return # of bytes in index file processed */ }; /* @@ -2038,12 +2038,12 @@ static void *load_cache_entries_thread(void *_data) return NULL; } -static unsigned long load_cache_entries_threaded(struct index_state *istate, const char *mmap, size_t mmap_size, - unsigned long src_offset, int nr_threads, struct index_entry_offset_table *ieot) +static size_t load_cache_entries_threaded(struct index_state *istate, const char *mmap, size_t mmap_size, + size_t src_offset, int nr_threads, struct index_entry_offset_table *ieot) { int i, offset, ieot_blocks, ieot_start, err; struct load_cache_entries_thread_data *data; - unsigned long consumed = 0; + size_t consumed = 0; /* a little sanity checking */ if (istate->name_hash_initialized) @@ -2114,7 +2114,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) { int fd; struct stat st; - unsigned long src_offset; + size_t src_offset; const struct cache_header *hdr; const char *mmap; size_t mmap_size; @@ -2423,7 +2423,7 @@ int repo_index_has_changes(struct repository *repo, #define WRITE_BUFFER_SIZE 8192 static unsigned char write_buffer[WRITE_BUFFER_SIZE]; -static unsigned long write_buffer_len; +static size_t write_buffer_len; static int ce_write_flush(git_hash_ctx *context, int fd) { @@ -3066,9 +3066,9 @@ static int write_split_index(struct index_state *istate, static const char *shared_index_expire = "2.weeks.ago"; -static unsigned long get_shared_index_expire_date(void) +static size_t get_shared_index_expire_date(void) { - static unsigned long shared_index_expire_date; + static size_t shared_index_expire_date; static int shared_index_expire_date_prepared; if (!shared_index_expire_date_prepared) { @@ -3084,7 +3084,7 @@ static unsigned long get_shared_index_expire_date(void) static int should_delete_shared_index(const char *shared_index_path) { struct stat st; - unsigned long expiration; + size_t expiration; /* Check timestamp */ expiration = get_shared_index_expire_date(); @@ -3325,10 +3325,10 @@ int index_name_is_other(const struct index_state *istate, const char *name, } void *read_blob_data_from_index(const struct index_state *istate, - const char *path, unsigned long *size) + const char *path, size_t *size) { int pos, len; - unsigned long sz; + size_t sz; enum object_type type; void *data; diff --git a/ref-filter.c b/ref-filter.c index 8500671bc60957..e76bd056fb618d 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -67,7 +67,7 @@ struct refname_atom { static struct expand_data { struct object_id oid; enum object_type type; - unsigned long size; + size_t size; off_t disk_size; struct object_id delta_base_oid; void *content; @@ -1018,7 +1018,7 @@ static const char *copy_email(const char *buf) return xmemdupz(email, eoemail + 1 - email); } -static char *copy_subject(const char *buf, unsigned long len) +static char *copy_subject(const char *buf, size_t len) { char *r = xmemdupz(buf, len); int i; @@ -1128,10 +1128,10 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void } static void find_subpos(const char *buf, - const char **sub, unsigned long *sublen, - const char **body, unsigned long *bodylen, - unsigned long *nonsiglen, - const char **sig, unsigned long *siglen) + const char **sub, size_t *sublen, + const char **body, size_t *bodylen, + size_t *nonsiglen, + const char **sig, size_t *siglen) { const char *eol; /* skip past header until we hit empty line */ @@ -1175,7 +1175,7 @@ static void find_subpos(const char *buf, * If 'lines' is greater than 0, append that many lines from the given * 'buf' of length 'size' to the given strbuf. */ -static void append_lines(struct strbuf *out, const char *buf, unsigned long size, int lines) +static void append_lines(struct strbuf *out, const char *buf, size_t size, int lines) { int i; const char *sp, *eol; @@ -1200,7 +1200,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) { int i; const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL; - unsigned long sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0; + size_t sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0; for (i = 0; i < used_atom_cnt; i++) { struct used_atom *atom = &used_atom[i]; diff --git a/remote-testsvn.c b/remote-testsvn.c index 3af708c5b67192..38f79aaf8acf17 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -56,7 +56,7 @@ static char *read_ref_note(const struct object_id *oid) { const struct object_id *note_oid; char *msg = NULL; - unsigned long msglen; + size_t msglen; enum object_type type; init_notes(NULL, notes_ref, NULL, 0); @@ -105,7 +105,7 @@ static int note2mark_cb(const struct object_id *object_oid, { FILE *file = (FILE *)cb_data; char *msg; - unsigned long msglen; + size_t msglen; enum object_type type; struct rev_note note; diff --git a/rerere.c b/rerere.c index 17abb47321f14a..4e1d5258179f93 100644 --- a/rerere.c +++ b/rerere.c @@ -973,7 +973,7 @@ static int handle_cache(struct index_state *istate, while (pos < istate->cache_nr) { enum object_type type; - unsigned long size; + size_t size; ce = istate->cache[pos++]; if (ce_namelen(ce) != len || memcmp(ce->name, path, len)) diff --git a/sha1-file.c b/sha1-file.c index 888b6024d5de05..7623bde5dfa994 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -208,7 +208,7 @@ static struct cached_object { struct object_id oid; enum object_type type; void *buf; - unsigned long size; + size_t size; } *cached_objects; static int cached_object_nr, cached_object_alloc; @@ -879,7 +879,7 @@ void *xmmap(void *start, size_t length, * the streaming interface and rehash it to do the same. */ int check_object_signature(const struct object_id *oid, void *map, - unsigned long size, const char *type) + size_t size, const char *type) { struct object_id real_oid; enum object_type obj_type; @@ -1015,7 +1015,7 @@ static int quick_has_loose(struct repository *r, * searching for a loose object named "oid". */ static void *map_loose_object_1(struct repository *r, const char *path, - const struct object_id *oid, unsigned long *size) + const struct object_id *oid, size_t *size) { void *map; int fd; @@ -1045,14 +1045,14 @@ static void *map_loose_object_1(struct repository *r, const char *path, void *map_loose_object(struct repository *r, const struct object_id *oid, - unsigned long *size) + size_t *size) { return map_loose_object_1(r, NULL, oid, size); } static int unpack_loose_short_header(git_zstream *stream, - unsigned char *map, unsigned long mapsize, - void *buffer, unsigned long bufsiz) + unsigned char *map, size_t mapsize, + void *buffer, size_t bufsiz) { /* Get the data stream */ memset(stream, 0, sizeof(*stream)); @@ -1066,8 +1066,8 @@ static int unpack_loose_short_header(git_zstream *stream, } int unpack_loose_header(git_zstream *stream, - unsigned char *map, unsigned long mapsize, - void *buffer, unsigned long bufsiz) + unsigned char *map, size_t mapsize, + void *buffer, size_t bufsiz) { int status = unpack_loose_short_header(stream, map, mapsize, buffer, bufsiz); @@ -1082,8 +1082,8 @@ int unpack_loose_header(git_zstream *stream, } static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map, - unsigned long mapsize, void *buffer, - unsigned long bufsiz, struct strbuf *header) + size_t mapsize, void *buffer, + size_t bufsiz, struct strbuf *header) { int status; @@ -1118,12 +1118,12 @@ static int unpack_loose_header_to_strbuf(git_zstream *stream, unsigned char *map } static void *unpack_loose_rest(git_zstream *stream, - void *buffer, unsigned long size, + void *buffer, size_t size, const struct object_id *oid) { int bytes = strlen(buffer) + 1; unsigned char *buf = xmallocz(size); - unsigned long n; + size_t n; int status = Z_OK; n = stream->total_out - bytes; @@ -1173,7 +1173,7 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi, unsigned int flags) { const char *type_buf = hdr; - unsigned long size; + size_t size; int type, type_len = 0; /* @@ -1213,7 +1213,7 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi, return -1; if (size) { for (;;) { - unsigned long c = *hdr - '0'; + size_t c = *hdr - '0'; if (c > 9) break; hdr++; @@ -1230,7 +1230,7 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi, return *hdr ? -1 : type; } -int parse_loose_header(const char *hdr, unsigned long *sizep) +int parse_loose_header(const char *hdr, size_t *sizep) { struct object_info oi = OBJECT_INFO_INIT; @@ -1243,12 +1243,12 @@ static int loose_object_info(struct repository *r, struct object_info *oi, int flags) { int status = 0; - unsigned long mapsize; + size_t mapsize; void *map; git_zstream stream; char hdr[MAX_HEADER_LEN]; struct strbuf hdrbuf = STRBUF_INIT; - unsigned long size_scratch; + size_t size_scratch; if (oi->delta_base_sha1) hashclr(oi->delta_base_sha1); @@ -1417,7 +1417,7 @@ int oid_object_info_extended(struct repository *r, const struct object_id *oid, /* returns enum object_type or negative */ int oid_object_info(struct repository *r, const struct object_id *oid, - unsigned long *sizep) + size_t *sizep) { enum object_type type; struct object_info oi = OBJECT_INFO_INIT; @@ -1432,7 +1432,7 @@ int oid_object_info(struct repository *r, static void *read_object(struct repository *r, const struct object_id *oid, enum object_type *type, - unsigned long *size) + size_t *size) { struct object_info oi = OBJECT_INFO_INIT; void *content; @@ -1445,7 +1445,7 @@ static void *read_object(struct repository *r, return content; } -int pretend_object_file(void *buf, unsigned long len, enum object_type type, +int pretend_object_file(void *buf, size_t len, enum object_type type, struct object_id *oid) { struct cached_object *co; @@ -1471,7 +1471,7 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type, void *read_object_file_extended(struct repository *r, const struct object_id *oid, enum object_type *type, - unsigned long *size, + size_t *size, int lookup_replace) { void *data; @@ -1507,12 +1507,12 @@ void *read_object_file_extended(struct repository *r, void *read_object_with_reference(const struct object_id *oid, const char *required_type_name, - unsigned long *size, + size_t *size, struct object_id *actual_oid_return) { enum object_type type, required_type; void *buffer; - unsigned long isize; + size_t isize; struct object_id actual_oid; required_type = type_from_string(required_type_name); @@ -1553,7 +1553,7 @@ void *read_object_with_reference(const struct object_id *oid, } } -static void write_object_file_prepare(const void *buf, unsigned long len, +static void write_object_file_prepare(const void *buf, size_t len, const char *type, struct object_id *oid, char *hdr, int *hdrlen) { @@ -1619,7 +1619,7 @@ static int write_buffer(int fd, const void *buf, size_t len) return 0; } -int hash_object_file(const void *buf, unsigned long len, const char *type, +int hash_object_file(const void *buf, size_t len, const char *type, struct object_id *oid) { char hdr[MAX_HEADER_LEN]; @@ -1683,7 +1683,7 @@ static int create_tmpfile(struct strbuf *tmp, const char *filename) } static int write_loose_object(const struct object_id *oid, char *hdr, - int hdrlen, const void *buf, unsigned long len, + int hdrlen, const void *buf, size_t len, time_t mtime) { int fd, ret; @@ -1773,7 +1773,7 @@ static int freshen_packed_object(const struct object_id *oid) return 1; } -int write_object_file(const void *buf, unsigned long len, const char *type, +int write_object_file(const void *buf, size_t len, const char *type, struct object_id *oid) { char hdr[MAX_HEADER_LEN]; @@ -1788,7 +1788,7 @@ int write_object_file(const void *buf, unsigned long len, const char *type, return write_loose_object(oid, hdr, hdrlen, buf, len, 0); } -int hash_object_file_literally(const void *buf, unsigned long len, +int hash_object_file_literally(const void *buf, size_t len, const char *type, struct object_id *oid, unsigned flags) { @@ -1814,7 +1814,7 @@ int hash_object_file_literally(const void *buf, unsigned long len, int force_object_loose(const struct object_id *oid, time_t mtime) { void *buf; - unsigned long len; + size_t len; enum object_type type; char hdr[MAX_HEADER_LEN]; int hdrlen; @@ -2257,14 +2257,14 @@ void odb_clear_loose_cache(struct object_directory *odb) static int check_stream_oid(git_zstream *stream, const char *hdr, - unsigned long size, + size_t size, const char *path, const struct object_id *expected_oid) { git_hash_ctx c; struct object_id real_oid; unsigned char buf[4096]; - unsigned long total_read; + size_t total_read; int status = Z_OK; the_hash_algo->init_fn(&c); @@ -2316,12 +2316,12 @@ static int check_stream_oid(git_zstream *stream, int read_loose_object(const char *path, const struct object_id *expected_oid, enum object_type *type, - unsigned long *size, + size_t *size, void **contents) { int ret = -1; void *map = NULL; - unsigned long mapsize; + size_t mapsize; git_zstream stream; char hdr[MAX_HEADER_LEN]; diff --git a/sha1dc_git.c b/sha1dc_git.c index e0cc9d988c7033..b24fc9af550ca2 100644 --- a/sha1dc_git.c +++ b/sha1dc_git.c @@ -25,7 +25,7 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx) /* * Same as SHA1DCUpdate, but adjust types to match git's usual interface. */ -void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len) +void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len) { const char *data = vdata; /* We expect an unsigned long, but sha1dc only takes an int */ diff --git a/sha1dc_git.h b/sha1dc_git.h index 41e1c3fd3f787e..847b38fb4b9f23 100644 --- a/sha1dc_git.h +++ b/sha1dc_git.h @@ -15,7 +15,7 @@ void git_SHA1DCInit(SHA1_CTX *); #endif void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *); -void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len); +void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, size_t len); #define platform_SHA_CTX SHA1_CTX #define platform_SHA1_Init git_SHA1DCInit diff --git a/streaming.c b/streaming.c index fcd63032192ff4..00771e8de7f58f 100644 --- a/streaming.c +++ b/streaming.c @@ -69,19 +69,19 @@ struct filtered_istream { struct git_istream { const struct stream_vtbl *vtbl; - unsigned long size; /* inflated size of full object */ + size_t size; /* inflated size of full object */ git_zstream z; enum { z_unused, z_used, z_done, z_error } z_state; union { struct { char *buf; /* from read_object() */ - unsigned long read_ptr; + size_t read_ptr; } incore; struct { void *mapped; - unsigned long mapsize; + size_t mapsize; char hdr[32]; int hdr_avail; int hdr_used; @@ -112,7 +112,7 @@ static enum input_source istream_source(const struct object_id *oid, enum object_type *type, struct object_info *oi) { - unsigned long size; + size_t size; int status; oi->typep = type; @@ -135,7 +135,7 @@ static enum input_source istream_source(const struct object_id *oid, struct git_istream *open_istream(const struct object_id *oid, enum object_type *type, - unsigned long *size, + size_t *size, struct stream_filter *filter) { struct git_istream *st; @@ -516,7 +516,7 @@ int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter { struct git_istream *st; enum object_type type; - unsigned long sz; + size_t sz; ssize_t kept = 0; int result = -1; diff --git a/streaming.h b/streaming.h index f465a3cd311ea7..fbf0e216191a41 100644 --- a/streaming.h +++ b/streaming.h @@ -8,7 +8,7 @@ /* opaque */ struct git_istream; -struct git_istream *open_istream(const struct object_id *, enum object_type *, unsigned long *, struct stream_filter *); +struct git_istream *open_istream(const struct object_id *, enum object_type *, size_t *, struct stream_filter *); int close_istream(struct git_istream *); ssize_t read_istream(struct git_istream *, void *, size_t); diff --git a/submodule-config.c b/submodule-config.c index 4264ee216f4977..9bd23774ec3d21 100644 --- a/submodule-config.c +++ b/submodule-config.c @@ -534,7 +534,7 @@ static const struct submodule *config_from(struct submodule_cache *cache, enum lookup_type lookup_type) { struct strbuf rev = STRBUF_INIT; - unsigned long config_size; + size_t config_size; char *config = NULL; struct object_id oid; enum object_type type; diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c index e749a49c88e66e..b613cd0216ac91 100644 --- a/t/helper/test-delta.c +++ b/t/helper/test-delta.c @@ -21,7 +21,7 @@ int cmd__delta(int argc, const char **argv) int fd; struct stat st; void *from_buf, *data_buf, *out_buf; - unsigned long from_size, data_size, out_size; + size_t from_size, data_size, out_size; if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) { fprintf(stderr, "usage: %s\n", usage_str); diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index 67fa0da5943452..2b1c30a9dc5875 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -70,6 +70,7 @@ static struct test_cmd cmds[] = { { "windows-named-pipe", cmd__windows_named_pipe }, #endif { "write-cache", cmd__write_cache }, + { "zlib-compile-flags", cmd__zlib_compile_flags }, }; static NORETURN void die_usage(void) diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index b223bbd5845f05..9e81b0e254bfc4 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -60,6 +60,7 @@ int cmd__wildmatch(int argc, const char **argv); int cmd__windows_named_pipe(int argc, const char **argv); #endif int cmd__write_cache(int argc, const char **argv); +int cmd__zlib_compile_flags(int argc, const char **argv); int cmd_hash_impl(int ac, const char **av, int algo); diff --git a/t/helper/test-zlib-compile-flags.c b/t/helper/test-zlib-compile-flags.c new file mode 100644 index 00000000000000..63e3525625120b --- /dev/null +++ b/t/helper/test-zlib-compile-flags.c @@ -0,0 +1,9 @@ +#include "test-tool.h" +#include "git-compat-util.h" +#include + +int cmd__zlib_compile_flags(int argc, const char **argv) +{ + printf("%lu\n", zlibCompileFlags()); + return 0; +} diff --git a/t/t-large-files-on-windows.sh b/t/t-large-files-on-windows.sh new file mode 100644 index 00000000000000..392c2e6acb10f3 --- /dev/null +++ b/t/t-large-files-on-windows.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +test_description='test large file handling on windows' +. ./test-lib.sh + +test_expect_success SIZE_T_IS_64BIT 'require 64bit size_t' ' + + test-tool zlib-compile-flags >zlibFlags.txt && + dd if=/dev/zero of=file bs=1M count=4100 && + git config core.compression 0 && + git config core.looseCompression 0 && + git add file && + git verify-pack -s .git/objects/pack/*.pack && + git fsck --verbose --strict --full && + git commit -m msg file && + git log --stat && + git gc && + git fsck --verbose --strict --full && + git index-pack -v -o test.idx .git/objects/pack/*.pack && + git gc && + git fsck +' + +test_done diff --git a/t/test-lib.sh b/t/test-lib.sh index 830157b4ab2906..3479b91d4a6987 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1617,6 +1617,10 @@ test_lazy_prereq LONG_IS_64BIT ' test 8 -le "$(build_option sizeof-long)" ' +test_lazy_prereq SIZE_T_IS_64BIT ' + test 8 -le "$(build_option sizeof-size_t)" +' + test_lazy_prereq TIME_IS_64BIT 'test-tool date is64bit' test_lazy_prereq TIME_T_IS_64BIT 'test-tool date time_t-is64bit' diff --git a/tag.c b/tag.c index 7445b8f6ea4d37..a6c07419dcaf26 100644 --- a/tag.c +++ b/tag.c @@ -41,7 +41,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report, { enum object_type type; char *buf; - unsigned long size; + size_t size; int ret; type = oid_object_info(the_repository, oid, NULL); @@ -132,7 +132,7 @@ void release_tag_memory(struct tag *t) t->date = 0; } -int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size) +int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, size_t size) { struct object_id oid; char type[20]; @@ -195,7 +195,7 @@ int parse_tag(struct tag *item) { enum object_type type; void *data; - unsigned long size; + size_t size; int ret; if (item->object.parsed) diff --git a/tag.h b/tag.h index 03265fbfe2942f..b4bb744b31ef1c 100644 --- a/tag.h +++ b/tag.h @@ -12,12 +12,12 @@ struct tag { timestamp_t date; }; struct tag *lookup_tag(struct repository *r, const struct object_id *oid); -int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, unsigned long size); +int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, size_t size); int parse_tag(struct tag *item); void release_tag_memory(struct tag *t); struct object *deref_tag(struct repository *r, struct object *, const char *, int); struct object *deref_tag_noverify(struct object *); int gpg_verify_tag(const struct object_id *oid, - const char *name_to_report, unsigned flags); + const char *name_to_report, unsigned flags); #endif /* TAG_H */ diff --git a/tree-walk.c b/tree-walk.c index ec32a47b2e7664..3205be7e5a8a09 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -83,7 +83,7 @@ int init_tree_desc_gently(struct tree_desc *desc, const void *buffer, unsigned l void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid) { - unsigned long size = 0; + size_t size = 0; void *buf = NULL; if (oid) { @@ -109,8 +109,8 @@ static int update_tree_entry_internal(struct tree_desc *desc, struct strbuf *err { const void *buf = desc->buffer; const unsigned char *end = (const unsigned char *)desc->entry.path + desc->entry.pathlen + 1 + the_hash_algo->rawsz; - unsigned long size = desc->size; - unsigned long len = end - (const unsigned char *)buf; + size_t size = desc->size; + size_t len = end - (const unsigned char *)buf; if (size < len) die(_("too-short tree file")); @@ -496,7 +496,7 @@ int traverse_trees(struct index_state *istate, struct dir_state { void *tree; - unsigned long size; + size_t size; struct object_id oid; }; @@ -539,7 +539,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob { int retval; void *tree; - unsigned long size; + size_t size; struct object_id root; tree = read_object_with_reference(tree_oid, tree_type, &size, &root); @@ -608,7 +608,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c if (!t.buffer) { void *tree; struct object_id root; - unsigned long size; + size_t size; tree = read_object_with_reference(¤t_tree_oid, tree_type, &size, &root); @@ -704,7 +704,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct object_id *tree_oid, c goto done; } else if (S_ISLNK(*mode)) { /* Follow a symlink */ - unsigned long link_len; + size_t link_len; size_t len; char *contents, *contents_start; struct dir_state *parent; diff --git a/tree.c b/tree.c index f416afc57d784f..e3bfb75c45b1e7 100644 --- a/tree.c +++ b/tree.c @@ -219,7 +219,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing) { enum object_type type; void *buffer; - unsigned long size; + size_t size; if (item->object.parsed) return 0; diff --git a/wrapper.c b/wrapper.c index ea3cf64d4c399a..0fe3f5b5fa2713 100644 --- a/wrapper.c +++ b/wrapper.c @@ -67,11 +67,11 @@ static void *do_xmalloc(size_t size, int gentle) ret = malloc(1); if (!ret) { if (!gentle) - die("Out of memory, malloc failed (tried to allocate %lu bytes)", - (unsigned long)size); + die("Out of memory, malloc failed (tried to allocate %" PRIuMAX " bytes)", + (uintmax_t)size); else { - error("Out of memory, malloc failed (tried to allocate %lu bytes)", - (unsigned long)size); + error("Out of memory, malloc failed (tried to allocate %" PRIuMAX " bytes)", + (uintmax_t)size); return NULL; } } @@ -703,3 +703,19 @@ int is_empty_or_missing_file(const char *filename) return !st.st_size; } + +uLong xcrc32(uLong crc, const unsigned char *buf, size_t bytes) +{ + size_t bytes_rem, off; + bytes_rem = bytes; + off = 0; + while (bytes_rem) { + int crc_bytes = maximum_signed_value_of_type(int); + if (crc_bytes > bytes_rem) + crc_bytes = bytes_rem; + crc = crc32(crc, buf + off, crc_bytes); + off += crc_bytes; + bytes_rem -= crc_bytes; + } + return crc; +} diff --git a/xdiff-interface.c b/xdiff-interface.c index 8509f9ea223a12..63039f6a37e69f 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -169,7 +169,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename) void read_mmblob(mmfile_t *ptr, const struct object_id *oid) { - unsigned long size; + size_t size; enum object_type type; if (oideq(oid, &null_oid)) { @@ -185,7 +185,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid) } #define FIRST_FEW_BYTES 8000 -int buffer_is_binary(const char *ptr, unsigned long size) +int buffer_is_binary(const char *ptr, size_t size) { if (FIRST_FEW_BYTES < size) size = FIRST_FEW_BYTES; diff --git a/xdiff-interface.h b/xdiff-interface.h index ede4246bbd3397..ccc87f3e7ab6f0 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -11,7 +11,7 @@ */ #define MAX_XDIFF_SIZE (1024UL * 1024 * 1023) -typedef void (*xdiff_emit_line_fn)(void *, char *, unsigned long); +typedef void (*xdiff_emit_line_fn)(void *, char *, size_t); typedef void (*xdiff_emit_hunk_fn)(void *data, long old_begin, long old_nr, long new_begin, long new_nr, @@ -25,7 +25,7 @@ int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg); int read_mmfile(mmfile_t *ptr, const char *filename); void read_mmblob(mmfile_t *ptr, const struct object_id *oid); -int buffer_is_binary(const char *ptr, unsigned long size); +int buffer_is_binary(const char *ptr, size_t size); void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags); void xdiff_clear_find_func(xdemitconf_t *xecfg); diff --git a/zlib.c b/zlib.c index d594cba3fc9d82..216b579dfa35d9 100644 --- a/zlib.c +++ b/zlib.c @@ -29,39 +29,29 @@ static const char *zerr_to_string(int status) */ /* #define ZLIB_BUF_MAX ((uInt)-1) */ #define ZLIB_BUF_MAX ((uInt) 1024 * 1024 * 1024) /* 1GB */ -static inline uInt zlib_buf_cap(unsigned long len) +static inline uInt zlib_buf_cap(size_t len) { - return (ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : len; + return ((size_t) ZLIB_BUF_MAX < len) ? ZLIB_BUF_MAX : (uInt) len; } static void zlib_pre_call(git_zstream *s) { s->z.next_in = s->next_in; s->z.next_out = s->next_out; - s->z.total_in = s->total_in; - s->z.total_out = s->total_out; + s->z.total_in = 0; + s->z.total_out = 0; s->z.avail_in = zlib_buf_cap(s->avail_in); s->z.avail_out = zlib_buf_cap(s->avail_out); } static void zlib_post_call(git_zstream *s) { - unsigned long bytes_consumed; - unsigned long bytes_produced; - - bytes_consumed = s->z.next_in - s->next_in; - bytes_produced = s->z.next_out - s->next_out; - if (s->z.total_out != s->total_out + bytes_produced) - BUG("total_out mismatch"); - if (s->z.total_in != s->total_in + bytes_consumed) - BUG("total_in mismatch"); - - s->total_out = s->z.total_out; - s->total_in = s->z.total_in; + s->total_out += (size_t) s->z.total_out; + s->total_in += (size_t) s->z.total_in; s->next_in = s->z.next_in; s->next_out = s->z.next_out; - s->avail_in -= bytes_consumed; - s->avail_out -= bytes_produced; + s->avail_in -= (size_t) s->z.total_in; + s->avail_out -= (size_t) s->z.total_out; } void git_inflate_init(git_zstream *strm) @@ -116,7 +106,7 @@ int git_inflate(git_zstream *strm, int flush) zlib_pre_call(strm); /* Never say Z_FINISH unless we are feeding everything */ status = inflate(&strm->z, - (strm->z.avail_in != strm->avail_in) + ((size_t) strm->z.avail_in != strm->avail_in) ? 0 : flush); if (status == Z_MEM_ERROR) die("inflate: out of memory"); @@ -150,7 +140,12 @@ int git_inflate(git_zstream *strm, int flush) #define deflateBound(c,s) ((s) + (((s) + 7) >> 3) + (((s) + 63) >> 6) + 11) #endif -unsigned long git_deflate_bound(git_zstream *strm, unsigned long size) + +/* + * The zlib deflateBound() 'size' is uLong. Define NO_DEFLATE_BOUND on + * Windows where uLong is only 32 bits and would result in data loss. + */ +size_t git_deflate_bound(git_zstream *strm, size_t size) { return deflateBound(&strm->z, size); } @@ -242,7 +237,7 @@ int git_deflate(git_zstream *strm, int flush) /* Never say Z_FINISH unless we are feeding everything */ status = deflate(&strm->z, - (strm->z.avail_in != strm->avail_in) + ((size_t) strm->z.avail_in != strm->avail_in) ? 0 : flush); if (status == Z_MEM_ERROR) die("deflate: out of memory");