Patchwork [3/3] target-i386: optimise [sg]et_cpu_mode_id

login
register
mail settings
Submitter liguang
Date Feb. 27, 2013, 1:17 a.m.
Message ID <1361927838-31197-3-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/223448/
State New
Headers show

Comments

liguang - Feb. 27, 2013, 1:17 a.m.
Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 target-i386/cpu.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Patch

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b92ee73..862f2dd 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1198,13 +1198,13 @@  static char *x86_cpuid_get_model_id(Object *obj, Error **errp)
     X86CPU *cpu = X86_CPU(obj);
     CPUX86State *env = &cpu->env;
     char *value;
-    int i;
+    int i, len = strlen((char *)env->cpuid_model);
 
-    value = g_malloc(48 + 1);
-    for (i = 0; i < 48; i++) {
+    value = g_malloc(len + 1);
+    for (i = 0; i < len; i++) {
         value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3));
     }
-    value[48] = '\0';
+    value[len + 1] = '\0';
     return value;
 }
 
@@ -1223,6 +1223,7 @@  static void x86_cpuid_set_model_id(Object *obj, const char *model_id,
     for (i = 0; i < 48; i++) {
         if (i >= len) {
             c = '\0';
+            break;
         } else {
             c = (uint8_t)model_id[i];
         }