bulk-checkin: fix sign compare warnings
In file bulk-checkin.c, three warnings are emitted by "-Wsign-compare", two of which are caused by trivial loop iterator type mismatches. For the third case, the type of `rsize` from ssize_t rsize = size < sizeof(ibuf) ? size : sizeof(ibuf); can be changed to size_t as both options of the ternary expression are unsigned and the signedness of the variable isn't really needed anywhere. To prevent `read_result != rsize` making a clash, it is to be noted that `read_result` is checked not to hold negative values. Therefore casting the variable to size_t is a safe operation and enough to remove the sign-compare warning. Fix issues accordingly, and remove `DISABLE_SIGN_COMPARE_WARNINGS` to enable "-Wsign-compare" for the file. Signed-off-by: Tuomas Ahola <taahol@utu.fi> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
683c54c999
commit
133d065dd6
@@ -3,7 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define USE_THE_REPOSITORY_VARIABLE
|
#define USE_THE_REPOSITORY_VARIABLE
|
||||||
#define DISABLE_SIGN_COMPARE_WARNINGS
|
|
||||||
|
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "bulk-checkin.h"
|
#include "bulk-checkin.h"
|
||||||
@@ -56,7 +55,6 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
|
|||||||
{
|
{
|
||||||
unsigned char hash[GIT_MAX_RAWSZ];
|
unsigned char hash[GIT_MAX_RAWSZ];
|
||||||
struct strbuf packname = STRBUF_INIT;
|
struct strbuf packname = STRBUF_INIT;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!state->f)
|
if (!state->f)
|
||||||
return;
|
return;
|
||||||
@@ -82,7 +80,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
|
|||||||
finish_tmp_packfile(&packname, state->pack_tmp_name,
|
finish_tmp_packfile(&packname, state->pack_tmp_name,
|
||||||
state->written, state->nr_written,
|
state->written, state->nr_written,
|
||||||
&state->pack_idx_opts, hash);
|
&state->pack_idx_opts, hash);
|
||||||
for (i = 0; i < state->nr_written; i++)
|
for (uint32_t i = 0; i < state->nr_written; i++)
|
||||||
free(state->written[i]);
|
free(state->written[i]);
|
||||||
|
|
||||||
clear_exit:
|
clear_exit:
|
||||||
@@ -131,14 +129,12 @@ static void flush_batch_fsync(void)
|
|||||||
|
|
||||||
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
|
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
/* The object may already exist in the repository */
|
/* The object may already exist in the repository */
|
||||||
if (repo_has_object_file(the_repository, oid))
|
if (repo_has_object_file(the_repository, oid))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Might want to keep the list sorted */
|
/* Might want to keep the list sorted */
|
||||||
for (i = 0; i < state->nr_written; i++)
|
for (uint32_t i = 0; i < state->nr_written; i++)
|
||||||
if (oideq(&state->written[i]->oid, oid))
|
if (oideq(&state->written[i]->oid, oid))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@@ -182,13 +178,13 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
|
|||||||
|
|
||||||
while (status != Z_STREAM_END) {
|
while (status != Z_STREAM_END) {
|
||||||
if (size && !s.avail_in) {
|
if (size && !s.avail_in) {
|
||||||
ssize_t rsize = size < sizeof(ibuf) ? size : sizeof(ibuf);
|
size_t rsize = size < sizeof(ibuf) ? size : sizeof(ibuf);
|
||||||
ssize_t read_result = read_in_full(fd, ibuf, rsize);
|
ssize_t read_result = read_in_full(fd, ibuf, rsize);
|
||||||
if (read_result < 0)
|
if (read_result < 0)
|
||||||
die_errno("failed to read from '%s'", path);
|
die_errno("failed to read from '%s'", path);
|
||||||
if (read_result != rsize)
|
if ((size_t)read_result != rsize)
|
||||||
die("failed to read %d bytes from '%s'",
|
die("failed to read %u bytes from '%s'",
|
||||||
(int)rsize, path);
|
(unsigned)rsize, path);
|
||||||
offset += rsize;
|
offset += rsize;
|
||||||
if (*already_hashed_to < offset) {
|
if (*already_hashed_to < offset) {
|
||||||
size_t hsize = offset - *already_hashed_to;
|
size_t hsize = offset - *already_hashed_to;
|
||||||
|
|||||||
Reference in New Issue
Block a user