From d18e9e686615c833491b350726d56931aed7075c Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sat, 19 May 2018 13:28:51 +0200
Subject: Fixed the loading of ARMv7 written-back registers.

---
 plugins/arm/v7/helpers.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/plugins/arm/v7/helpers.h b/plugins/arm/v7/helpers.h
index a863a2d..3f8d97c 100644
--- a/plugins/arm/v7/helpers.h
+++ b/plugins/arm/v7/helpers.h
@@ -389,26 +389,34 @@
     })
 
 
-#define UncheckedWrittenBackReg(reg)                                                \
+#define UncheckedWrittenBackReg(regop)                                              \
     ({                                                                              \
         GArchOperand *__result;                                                     \
-        if (reg == NULL)                                                            \
+        GArchRegister *__reg;                                                       \
+        if (regop == NULL)                                                          \
             __result = NULL;                                                        \
         else                                                                        \
-            __result = g_armv7_register_operand_new(G_ARMV7_REGISTER(reg));         \
+        {                                                                           \
+            __reg = g_register_operand_get_register(G_REGISTER_OPERAND(regop));     \
+            g_object_unref(G_OBJECT(regop));                                        \
+            __result = g_armv7_register_operand_new(G_ARMV7_REGISTER(__reg));       \
+        }                                                                           \
         __result;                                                                   \
     })
 
 
-#define WrittenBackReg(reg, writeback)                                              \
+#define WrittenBackReg(regop, writeback)                                            \
     ({                                                                              \
         GArchOperand *__result;                                                     \
+        GArchRegister *__reg;                                                       \
         GArmV7RegisterOperand *__armv7_op;                                          \
-        if (reg == NULL)                                                            \
+        if (regop == NULL)                                                          \
             __result = NULL;                                                        \
         else                                                                        \
         {                                                                           \
-            __result = g_armv7_register_operand_new(G_ARMV7_REGISTER(reg));         \
+            __reg = g_register_operand_get_register(G_REGISTER_OPERAND(regop));     \
+            g_object_unref(G_OBJECT(regop));                                        \
+            __result = g_armv7_register_operand_new(G_ARMV7_REGISTER(__reg));       \
             if (__result != NULL && writeback == 1)                                 \
             {                                                                       \
                 __armv7_op = G_ARMV7_REGISTER_OPERAND(__result);                    \
-- 
cgit v0.11.2-87-g4458