summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/mmap.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-01-08 11:12:14 +0100
committerJulian Andres Klode <jak@debian.org>2016-01-08 21:20:25 +0100
commit60d523e2ae93a6c5bc396b6bede2544271fb1f2e (patch)
tree949bac3513d69f66d7df6dbc92afca564b2eb8b6 /apt-pkg/contrib/mmap.cc
parentaf4899c9df6e925b1cb099c29bd78788b2984cca (diff)
downloadapt-60d523e2ae93a6c5bc396b6bede2544271fb1f2e.tar.gz
Store the size of strings in the cache
By storing the size of the string in the cache, we can make use of it when comparing the names in the hashtable in pkgCache::FindGrp.
Diffstat (limited to 'apt-pkg/contrib/mmap.cc')
-rw-r--r--apt-pkg/contrib/mmap.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index 4dc851c1b..74870b404 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -411,7 +411,7 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
/*}}}*/
// DynamicMMap::WriteString - Write a string to the file /*{{{*/
// ---------------------------------------------------------------------
-/* Strings are not aligned to anything */
+/* Strings are aligned to 16 bytes */
unsigned long DynamicMMap::WriteString(const char *String,
unsigned long Len)
{
@@ -419,13 +419,20 @@ unsigned long DynamicMMap::WriteString(const char *String,
Len = strlen(String);
_error->PushToStack();
- unsigned long const Result = RawAllocate(Len+1,0);
+ unsigned long Result = RawAllocate(Len+1+sizeof(uint16_t),sizeof(uint16_t));
bool const newError = _error->PendingError();
_error->MergeWithStack();
if (Base == NULL || (Result == 0 && newError))
return 0;
+ if (Len >= std::numeric_limits<uint16_t>::max())
+ abort();
+
+ uint16_t LenToWrite = Len;
+ memcpy((char *)Base + Result, &LenToWrite, sizeof(LenToWrite));
+ Result += + sizeof(LenToWrite);
+
memcpy((char *)Base + Result,String,Len);
((char *)Base)[Result + Len] = 0;
return Result;