From 9cc52c75e30c434863f6bcf89205ff0178a7bb89 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 18 Jun 2017 23:47:24 +0300 Subject: [PATCH] Fix hex_to_bytes --- rpcs3/Crypto/utils.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/rpcs3/Crypto/utils.cpp b/rpcs3/Crypto/utils.cpp index b2d945178f..6a31a7e766 100644 --- a/rpcs3/Crypto/utils.cpp +++ b/rpcs3/Crypto/utils.cpp @@ -2,9 +2,9 @@ // Licensed under the terms of the GNU GPL, version 3 // http://www.gnu.org/licenses/gpl-3.0.txt -#include "utils.h" -#include -#include +#include "utils.h" +#include +#include #include #include @@ -52,28 +52,22 @@ u64 hex_to_u64(const char* hex_str) return result; } -void hex_to_bytes(unsigned char *data, const char *hex_str, unsigned int str_length) +void hex_to_bytes(unsigned char* data, const char* hex_str, unsigned int str_length) { - u32 strn_length = (str_length > 0) ? str_length : (u32) strlen(hex_str); + u32 strn_length = (str_length > 0) ? str_length : (u32)std::strlen(hex_str); u32 data_length = strn_length / 2; char tmp_buf[3] = {0, 0, 0}; // Don't convert if the string length is odd. - if (!(strn_length % 2)) + if ((strn_length % 2) == 0) { - auto out = std::make_unique(strn_length * sizeof(u8)); - u8 *pos = out.get(); - - while (strn_length--) + while (data_length--) { tmp_buf[0] = *hex_str++; tmp_buf[1] = *hex_str++; - *pos++ = (u8)(hex_to_u64(tmp_buf) & 0xFF); + *data++ = (u8)(hex_to_u64(tmp_buf) & 0xFF); } - - // Copy back to our array. - memcpy(data, out.get(), data_length); } }