commit - 7426bbfd0325eb69b703734636662a9968c36888
commit + 3fe2daf1bfa78990045d9613e9b797437ac7f361
blob - e860a4dace549dfb77ad350dc3fce155b64dfdc1
blob + 86250c11fe57924c5ca80e01cac4cd1188d8e075
--- lib/fileindex.c
+++ lib/fileindex.c
static const struct got_error *
write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
{
- uint8_t buf[sizeof(uint64_t)];
size_t n;
val = htobe64(val);
- memcpy(buf, &val, sizeof(val));
- SHA1Update(ctx, buf, sizeof(val));
- n = fwrite(buf, 1, sizeof(val), outfile);
+ SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
+ n = fwrite(&val, 1, sizeof(val), outfile);
if (n != sizeof(val))
return got_ferror(outfile, GOT_ERR_IO);
return NULL;
static const struct got_error *
write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
{
- uint8_t buf[sizeof(uint32_t)];
size_t n;
val = htobe32(val);
- memcpy(buf, &val, sizeof(val));
- SHA1Update(ctx, buf, sizeof(val));
- n = fwrite(buf, 1, sizeof(val), outfile);
+ SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
+ n = fwrite(&val, 1, sizeof(val), outfile);
if (n != sizeof(val))
return got_ferror(outfile, GOT_ERR_IO);
return NULL;
static const struct got_error *
write_fileindex_val16(SHA1_CTX *ctx, uint16_t val, FILE *outfile)
{
- uint8_t buf[sizeof(uint16_t)];
size_t n;
val = htobe16(val);
- memcpy(buf, &val, sizeof(val));
- SHA1Update(ctx, buf, sizeof(val));
- n = fwrite(buf, 1, sizeof(val), outfile);
+ SHA1Update(ctx, (uint8_t *)&val, sizeof(val));
+ n = fwrite(&val, 1, sizeof(val), outfile);
if (n != sizeof(val))
return got_ferror(outfile, GOT_ERR_IO);
return NULL;
static const struct got_error *
read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
{
- uint8_t buf[sizeof(uint64_t)];
size_t n;
- n = fread(buf, 1, sizeof(buf), infile);
- if (n != sizeof(buf))
+ n = fread(val, 1, sizeof(*val), infile);
+ if (n != sizeof(*val))
return got_ferror(infile, GOT_ERR_IO);
- SHA1Update(ctx, buf, sizeof(buf));
- memcpy(val, buf, sizeof(*val));
+ SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
*val = be64toh(*val);
return NULL;
}
static const struct got_error *
read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
{
- uint8_t buf[sizeof(uint32_t)];
size_t n;
- n = fread(buf, 1, sizeof(buf), infile);
- if (n != sizeof(buf))
+ n = fread(val, 1, sizeof(*val), infile);
+ if (n != sizeof(*val))
return got_ferror(infile, GOT_ERR_IO);
- SHA1Update(ctx, buf, sizeof(buf));
- memcpy(val, buf, sizeof(*val));
+ SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
*val = be32toh(*val);
return NULL;
}
static const struct got_error *
read_fileindex_val16(uint16_t *val, SHA1_CTX *ctx, FILE *infile)
{
- uint8_t buf[sizeof(uint16_t)];
size_t n;
- n = fread(buf, 1, sizeof(buf), infile);
- if (n != sizeof(buf))
+ n = fread(val, 1, sizeof(*val), infile);
+ if (n != sizeof(*val))
return got_ferror(infile, GOT_ERR_IO);
- SHA1Update(ctx, buf, sizeof(buf));
- memcpy(val, buf, sizeof(*val));
+ SHA1Update(ctx, (uint8_t *)val, sizeof(*val));
*val = be16toh(*val);
return NULL;
}