From 9c687a6f70a7b88b8e8c125421c5f5e765b928a5 Mon Sep 17 00:00:00 2001 From: Gabor Dozsa Date: Tue, 7 Nov 2017 14:05:00 +0000 Subject: [PATCH] arch: Fix unserialization of VectorReg value Change-Id: Iba01ae60e10703877eae299ba924fa1f04a4a387 Signed-off-by: Giacomo Gabrielli Reviewed-on: https://gem5-review.googlesource.com/13104 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg --- src/arch/generic/vec_reg.hh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/arch/generic/vec_reg.hh b/src/arch/generic/vec_reg.hh index b68a5886d..7145af4cf 100644 --- a/src/arch/generic/vec_reg.hh +++ b/src/arch/generic/vec_reg.hh @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016 ARM Limited + * Copyright (c) 2015-2016, 2018 ARM Limited * All rights reserved * * The license below extends only to copyright in the software and shall @@ -635,11 +635,14 @@ template inline bool to_number(const std::string& value, VecRegContainer& v) { - int i = 0; - while (i < Sz) { - std::string byte = value.substr(i<<1, 2); - v.template raw_ptr()[i] = stoul(byte, 0, 16); - i++; + fatal_if(value.size() > 2 * VecRegContainer::SIZE, + "Vector register value overflow at unserialize"); + + for (int i = 0; i < VecRegContainer::SIZE; i++) { + uint8_t b = 0; + if (2 * i < value.size()) + b = stoul(value.substr(i * 2, 2), nullptr, 16); + v.template raw_ptr()[i] = b; } return true; } -- 2.30.2