summaryrefslogtreecommitdiff
path: root/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2021-08-29 04:06:16 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2021-08-29 04:06:16 +0000
commite2861beed768a741fd41e8df0ab6a74f5b583d05 (patch)
treec4fcc6aa758b08701034e3be0e6abdcab99c64ad /Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
parent28456f9ecb080a4c3c43336b6dfb5d72a9cc528a (diff)
harfbuzz 2.9.0
git-svn-id: svn://tug.org/texlive/trunk@60356 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh')
-rw-r--r--Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh42
1 files changed, 25 insertions, 17 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
index 3ec055b7b0b..5e07bb82387 100644
--- a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
+++ b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
@@ -82,7 +82,7 @@ struct hb_serialize_context_t
struct link_t
{
- bool is_wide: 1;
+ unsigned width: 3;
bool is_signed: 1;
unsigned whence: 2;
unsigned position: 28;
@@ -254,7 +254,7 @@ struct hb_serialize_context_t
current = current->next;
revert (obj->head, obj->tail);
obj->fini ();
- object_pool.free (obj);
+ object_pool.release (obj);
}
/* Set share to false when an object is unlikely sharable with others
@@ -354,7 +354,6 @@ struct hb_serialize_context_t
whence_t whence = Head,
unsigned bias = 0)
{
- static_assert (sizeof (T) == 2 || sizeof (T) == 4, "");
if (unlikely (in_error ())) return;
if (!objidx)
@@ -365,7 +364,7 @@ struct hb_serialize_context_t
auto& link = *current->links.push ();
- link.is_wide = sizeof (T) == 4;
+ link.width = sizeof (T);
link.is_signed = hb_is_signed (hb_unwrap_type (T));
link.whence = (unsigned) whence;
link.position = (const char *) &ofs - current->head;
@@ -405,15 +404,19 @@ struct hb_serialize_context_t
offset -= link.bias;
if (link.is_signed)
{
- if (link.is_wide)
+ assert (link.width == 2 || link.width == 4);
+ if (link.width == 4)
assign_offset<int32_t> (parent, link, offset);
else
assign_offset<int16_t> (parent, link, offset);
}
else
{
- if (link.is_wide)
+ assert (link.width == 2 || link.width == 3 || link.width == 4);
+ if (link.width == 4)
assign_offset<uint32_t> (parent, link, offset);
+ else if (link.width == 3)
+ assign_offset<uint32_t, 3> (parent, link, offset);
else
assign_offset<uint16_t> (parent, link, offset);
}
@@ -446,16 +449,16 @@ struct hb_serialize_context_t
}
template <typename Type>
- Type *allocate_size (unsigned int size)
+ Type *allocate_size (size_t size)
{
if (unlikely (in_error ())) return nullptr;
- if (this->tail - this->head < ptrdiff_t (size))
+ if (unlikely (size > INT_MAX || this->tail - this->head < ptrdiff_t (size)))
{
err (HB_SERIALIZE_ERROR_OUT_OF_ROOM);
return nullptr;
}
- memset (this->head, 0, size);
+ hb_memset (this->head, 0, size);
char *ret = this->head;
this->head += size;
return reinterpret_cast<Type *> (ret);
@@ -510,18 +513,19 @@ struct hb_serialize_context_t
hb_serialize_context_t& operator << (const Type &obj) & { embed (obj); return *this; }
template <typename Type>
- Type *extend_size (Type *obj, unsigned int size)
+ Type *extend_size (Type *obj, size_t size)
{
if (unlikely (in_error ())) return nullptr;
assert (this->start <= (char *) obj);
assert ((char *) obj <= this->head);
- assert ((char *) obj + size >= this->head);
- if (unlikely (!this->allocate_size<Type> (((char *) obj) + size - this->head))) return nullptr;
+ assert ((size_t) (this->head - (char *) obj) <= size);
+ if (unlikely (((char *) obj + size < (char *) obj) ||
+ !this->allocate_size<Type> (((char *) obj) + size - this->head))) return nullptr;
return reinterpret_cast<Type *> (obj);
}
template <typename Type>
- Type *extend_size (Type &obj, unsigned int size)
+ Type *extend_size (Type &obj, size_t size)
{ return extend_size (hb_addressof (obj), size); }
template <typename Type>
@@ -544,7 +548,11 @@ struct hb_serialize_context_t
unsigned int len = (this->head - this->start)
+ (this->end - this->tail);
- char *p = (char *) malloc (len);
+ // If len is zero don't hb_malloc as the memory won't get properly
+ // cleaned up later.
+ if (!len) return hb_bytes_t ();
+
+ char *p = (char *) hb_malloc (len);
if (unlikely (!p)) return hb_bytes_t ();
memcpy (p, this->start, this->head - this->start);
@@ -559,17 +567,17 @@ struct hb_serialize_context_t
hb_bytes_t b = copy_bytes ();
return hb_blob_create (b.arrayZ, b.length,
HB_MEMORY_MODE_WRITABLE,
- (char *) b.arrayZ, free);
+ (char *) b.arrayZ, hb_free);
}
const hb_vector_t<object_t *>& object_graph() const
{ return packed; }
private:
- template <typename T>
+ template <typename T, unsigned Size = sizeof (T)>
void assign_offset (const object_t* parent, const object_t::link_t &link, unsigned offset)
{
- auto &off = * ((BEInt<T> *) (parent->head + link.position));
+ auto &off = * ((BEInt<T, Size> *) (parent->head + link.position));
assert (0 == off);
check_assign (off, offset, HB_SERIALIZE_ERROR_OFFSET_OVERFLOW);
}