Kelson has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/296644 )
Change subject: Bug fix: don't store pointers inside a dynamic vector.
......................................................................
Bug fix: don't store pointers inside a dynamic vector.
Use offsets instead, since the actual objects change location whenever
the std::vector resizes its internal storage.
This is a follow-up to f5de40f94b30795f42bb9388cbb46df9cd605167.
Change-Id: I166aa8dd209dd2755e68be70829f269a71a3aaca
---
M zimlib/include/zim/writer/zimcreator.h
M zimlib/src/zimcreator.cpp
2 files changed, 10 insertions(+), 8 deletions(-)
Approvals:
Kelson: Verified; Looks good to me, approved
diff --git a/zimlib/include/zim/writer/zimcreator.h
b/zimlib/include/zim/writer/zimcreator.h
index 2e52d7e..8ce2c44 100644
--- a/zimlib/include/zim/writer/zimcreator.h
+++ b/zimlib/include/zim/writer/zimcreator.h
@@ -33,7 +33,7 @@
{
public:
typedef std::vector<Dirent> DirentsType;
- typedef std::vector<Dirent*> DirentPtrsType;
+ typedef std::vector<DirentsType::size_type> DirentPtrsType;
typedef std::vector<size_type> SizeVectorType;
typedef std::vector<offset_type> OffsetsType;
typedef std::map<std::string, uint16_t> MimeTypes;
diff --git a/zimlib/src/zimcreator.cpp b/zimlib/src/zimcreator.cpp
index 46c550f..9c024a7 100644
--- a/zimlib/src/zimcreator.cpp
+++ b/zimlib/src/zimcreator.cpp
@@ -232,7 +232,7 @@
}
dirents.back().setCluster(clusterOffsets.size(), cluster->count());
cluster->addBlob(blob);
- myDirents->push_back(&(dirents.back()));
+ myDirents->push_back(dirents.size()-1);
// If cluster is now large enough, write it to disk.
if (cluster->size() >= minChunkSize * 1024)
@@ -247,10 +247,11 @@
cluster->clear();
myDirents->clear();
// Update the cluster number of the dirents *not* written to disk.
- for (DirentPtrsType::iterator di = otherDirents->begin();
- di != otherDirents->end(); ++di)
+ for (DirentPtrsType::iterator dpi = otherDirents->begin();
+ dpi != otherDirents->end(); ++dpi)
{
- (*di)->setCluster(clusterOffsets.size(), (*di)->getBlobNumber());
+ Dirent *di = &dirents[*dpi];
+ di->setCluster(clusterOffsets.size(), di->getBlobNumber());
}
offset_type end = out.tellp();
currentSize += (end - start) +
@@ -263,10 +264,11 @@
{
clusterOffsets.push_back(out.tellp());
out << compCluster;
- for (DirentPtrsType::iterator di = uncompDirents.begin();
- di != uncompDirents.end(); ++di)
+ for (DirentPtrsType::iterator dpi = uncompDirents.begin();
+ dpi != uncompDirents.end(); ++dpi)
{
- (*di)->setCluster(clusterOffsets.size(), (*di)->getBlobNumber());
+ Dirent *di = &dirents[*dpi];
+ di->setCluster(clusterOffsets.size(), di->getBlobNumber());
}
}
compCluster.clear();
--
To view, visit https://gerrit.wikimedia.org/r/296644
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I166aa8dd209dd2755e68be70829f269a71a3aaca
Gerrit-PatchSet: 1
Gerrit-Project: openzim
Gerrit-Branch: master
Gerrit-Owner: C. Scott Ananian <[email protected]>
Gerrit-Reviewer: Kelson <[email protected]>
Gerrit-Reviewer: Mgautierfr <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits