remove pointless memcopies from fileindex code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/lib/fileindex.c b/lib/fileindex.c
index e860a4d..86250c1 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -116,13 +116,11 @@ got_fileindex_free(struct got_fileindex *fileindex)
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;
@@ -131,13 +129,11 @@ write_fileindex_val64(SHA1_CTX *ctx, uint64_t val, FILE *outfile)
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;
@@ -146,13 +142,11 @@ write_fileindex_val32(SHA1_CTX *ctx, uint32_t val, FILE *outfile)
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;
@@ -269,14 +263,12 @@ got_fileindex_write(struct got_fileindex *fileindex, FILE *outfile)
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;
}
@@ -284,14 +276,12 @@ read_fileindex_val64(uint64_t *val, SHA1_CTX *ctx, FILE *infile)
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;
}
@@ -299,14 +289,12 @@ read_fileindex_val32(uint32_t *val, SHA1_CTX *ctx, FILE *infile)
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;
}