From 398b05afedef6899d2a7c7d083d48653d896be74 Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Sat, 30 Nov 2013 10:59:05 -0500 Subject: [PATCH] Fix uninit'd memory issues in AMTL AString and Vector (bug 5921, r=psychonic). --HG-- extra : rebase_source : 17a57dcf815cb3798eaa13af5f4af44fb1930f86 --- public/amtl/am-string.h | 2 ++ public/amtl/am-vector.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/public/amtl/am-string.h b/public/amtl/am-string.h index 1d1b7e2a9..074339fa1 100644 --- a/public/amtl/am-string.h +++ b/public/amtl/am-string.h @@ -55,6 +55,8 @@ class AString AString(const AString &other) { if (other.length_) set(other.chars_, other.length_); + else + length_ = 0; } AString(Moveable other) : chars_(other->chars_.take()), diff --git a/public/amtl/am-vector.h b/public/amtl/am-vector.h index 2e88cc339..2b0b8feb0 100644 --- a/public/amtl/am-vector.h +++ b/public/amtl/am-vector.h @@ -187,10 +187,10 @@ class Vector : public AllocPolicy bool moveUp(size_t at) { assert(at < nitems_); - if (!growIfNeeded(1)) + if (!append(Moveable(data_[nitems_ - 1]))) return false; - nitems_++; - for (size_t i = nitems_ - 1; i > at; i--) + + for (size_t i = nitems_ - 2; i > at; i--) data_[i] = Moveable(data_[i - 1]); return true; }