commit a5744d7100b84f5998fe87f7a2ff3637fd28be64 from: Stefan Sperling date: Sat Jan 12 22:00:44 2019 UTC don't bother with memcpy of header when writing the file index commit - 784955db0f639c53fd5aeb70d0f006cad99a815f commit + a5744d7100b84f5998fe87f7a2ff3637fd28be64 blob - afdeab746035bdafbbd04d8bf67736896f49b640 blob + 4562e971c3719cdb1db04abc44e8a19bd0de5a5b --- lib/fileindex.c +++ lib/fileindex.c @@ -300,9 +300,6 @@ got_fileindex_write(struct got_fileindex *fileindex, F SHA1_CTX ctx; uint8_t sha1[SHA1_DIGEST_LENGTH]; size_t n; - const size_t len = sizeof(hdr.signature) + sizeof(hdr.version) + - sizeof(hdr.nentries); - uint8_t buf[len]; struct got_fileindex_entry *entry; SHA1Init(&ctx); @@ -311,11 +308,18 @@ got_fileindex_write(struct got_fileindex *fileindex, F hdr.version = htobe32(GOT_FILE_INDEX_VERSION); hdr.nentries = htobe32(fileindex->nentries); - memcpy(buf, &hdr, len); - SHA1Update(&ctx, buf, len); - n = fwrite(buf, 1, len, outfile); - if (n != len) + SHA1Update(&ctx, (uint8_t *)&hdr.signature, sizeof(hdr.signature)); + SHA1Update(&ctx, (uint8_t *)&hdr.version, sizeof(hdr.version)); + SHA1Update(&ctx, (uint8_t *)&hdr.nentries, sizeof(hdr.nentries)); + n = fwrite(&hdr.signature, 1, sizeof(hdr.signature), outfile); + if (n != sizeof(hdr.signature)) + return got_ferror(outfile, GOT_ERR_IO); + n = fwrite(&hdr.version, 1, sizeof(hdr.version), outfile); + if (n != sizeof(hdr.version)) return got_ferror(outfile, GOT_ERR_IO); + n = fwrite(&hdr.nentries, 1, sizeof(hdr.nentries), outfile); + if (n != sizeof(hdr.nentries)) + return got_ferror(outfile, GOT_ERR_IO); RB_FOREACH(entry, got_fileindex_tree, &fileindex->entries) { entry->flags &= ~GOT_INDEX_ENTRY_F_INTENT_TO_ADD;