A few more cases to populate the hash in addpool

This commit is contained in:
Erica Fischer
2024-02-02 14:12:34 -08:00
parent 353cdf16e6
commit 4b8574aa87
4 changed files with 24 additions and 10 deletions
+18 -7
View File
@@ -64,14 +64,20 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
// the pool is full yet.
long long off = poolfile->off;
if (memfile_write(poolfile, &type, 1) < 0) {
bool in_memory = false;
if (memfile_write(poolfile, &type, 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
if (memfile_write(poolfile, (void *) s, strlen(s) + 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (in_memory) {
dedup[hash_off] = off;
}
return off;
}
}
@@ -94,11 +100,12 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
// to the newly-added strings.
long long off = poolfile->off;
if (memfile_write(poolfile, &type, 1) < 0) {
bool in_memory;
if (memfile_write(poolfile, &type, 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
if (memfile_write(poolfile, (void *) s, strlen(s) + 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
@@ -114,14 +121,18 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
}
long long off = poolfile->off;
if (memfile_write(poolfile, &type, 1) < 0) {
bool in_memory = false;
if (memfile_write(poolfile, &type, 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (memfile_write(poolfile, (void *) s, strlen(s) + 1) < 0) {
if (memfile_write(poolfile, (void *) s, strlen(s) + 1, in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}
if (in_memory) {
dedup[hash_off] = off;
}
if (off >= LONG_MAX || treefile->off >= LONG_MAX) {
// Tree or pool is bigger than 2GB
@@ -139,7 +150,7 @@ long long addpool(struct memfile *poolfile, struct memfile *treefile, const char
tsp.off = off;
long long p = treefile->off;
if (memfile_write(treefile, &tsp, sizeof(struct stringpool)) < 0) {
if (memfile_write(treefile, &tsp, sizeof(struct stringpool), in_memory) < 0) {
perror("memfile write");
exit(EXIT_WRITE);
}