Skip to contentSkip to conversation

Fix vmstate_info_int32_le comparison/assign

PATCH New Dr. David Alan Gilbert (git) 1 participant 1 message Feb 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Fix vmstate_info_int32_le comparison/assign

From: "Dr. David Alan Gilbert" <[email protected]>

Fix comparison of vmstate_info_int32_le so that it succeeds if loaded value is (l)ess than or (e)qual

When the comparison succeeds, assign the value loaded
This is a change in behaviour but I think the original intent, since the idea is to check if the version/size of the thing you're loading is less than some limit, but you might well want to do something based on the actual version/size in the file

Fix up comment and name text

---

V2
Just missed the signed-off-by

 vmstate.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
vmstate.c +8 -7
index 284b080..d1f5eb0 100644
@@ -321,23 +321,24 @@ const VMStateInfo vmstate_info_int32_equal = {
     .put  = put_int32,
 };
 
-/* 32 bit int. See that the received value is the less or the same
-   than the one in the field */
+/* 32 bit int. Check that the received value is less than or equal to
+   the one in the field */
 
 static int get_int32_le(QEMUFile *f, void *pv, size_t size)
 {
-    int32_t *old = pv;
-    int32_t new;
-    qemu_get_sbe32s(f, &new);
+    int32_t *cur = pv;
+    int32_t loaded;
+    qemu_get_sbe32s(f, &loaded);
 
-    if (*old <= new) {
+    if (loaded <= *cur) {
+        *cur = loaded;
         return 0;
     }
     return -EINVAL;
 }
 
 const VMStateInfo vmstate_info_int32_le = {
-    .name = "int32 equal",
+    .name = "int32 le",
     .get  = get_int32_le,
     .put  = put_int32,
 };
Signature · 1 line
1.8.5.3