commit ac62b7128d19ff467525fe11e07efdbc47c53bb5 from: Stefan Sperling date: Tue Mar 30 14:50:44 2021 UTC when reading a pack index byte-swap fields at compile-time where possible suggested by mpi@ ages ago commit - 6c41426143b93f57eebf1aaac35dcee4fa3fc282 commit + ac62b7128d19ff467525fe11e07efdbc47c53bb5 blob - 712b0f55c1bb511c3d3829528964d5036a503d9d blob + ee37e1005b535f08ac796a6547d42f3394b34916 --- lib/pack.c +++ lib/pack.c @@ -106,7 +106,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify goto done; } } - if (be32toh(*h->magic) != GOT_PACKIDX_V2_MAGIC) { + if (*h->magic != htobe32(GOT_PACKIDX_V2_MAGIC)) { err = got_error(GOT_ERR_BAD_PACKIDX); goto done; } @@ -137,7 +137,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify goto done; } } - if (be32toh(*h->version) != GOT_PACKIDX_VERSION) { + if (*h->version != htobe32(GOT_PACKIDX_VERSION)) { err = got_error(GOT_ERR_BAD_PACKIDX); goto done; } @@ -259,8 +259,8 @@ got_packidx_init_hdr(struct got_packidx *p, int verify /* Large file offsets are contained only in files > 2GB. */ for (i = 0; i < nobj; i++) { - uint32_t o = be32toh(h->offsets[i]); - if (o & GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX) + uint32_t o = h->offsets[i]; + if (o & htobe32(GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX)) p->nlargeobj++; } if (p->nlargeobj == 0)