From b3b7271fbda1ef5fc5d2dbdbd473d6ea627a1aa8 Mon Sep 17 00:00:00 2001 From: Tooru Fujisawa Date: Tue, 17 Sep 2019 15:46:36 +0000 Subject: [PATCH] Bug 1581880 - Remove loop from BinASTTokenReaderBase::readByte. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D46164 --HG-- extra : moz-landing-system : lando --- js/src/frontend/BinASTTokenReaderBase.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/js/src/frontend/BinASTTokenReaderBase.cpp b/js/src/frontend/BinASTTokenReaderBase.cpp index f8456e8da75a..c64d8e08ab6c 100644 --- a/js/src/frontend/BinASTTokenReaderBase.cpp +++ b/js/src/frontend/BinASTTokenReaderBase.cpp @@ -98,9 +98,13 @@ JS::Result BinASTTokenReaderBase::readBuf(uint8_t* bytes, uint32_t len) { } JS::Result BinASTTokenReaderBase::readByte() { - uint8_t byte; - MOZ_TRY(readBuf(&byte, 1)); - return byte; + MOZ_ASSERT(!hasRaisedError()); + + if (MOZ_UNLIKELY(stop_ == current_)) { + return raiseError("Buffer exceeds length"); + } + + return *current_++; } } // namespace frontend