diff --git a/bochs/gui/enh_dbg.cc b/bochs/gui/enh_dbg.cc index 50832bbf1..048bd4e7a 100644 --- a/bochs/gui/enh_dbg.cc +++ b/bochs/gui/enh_dbg.cc @@ -3443,11 +3443,11 @@ BxEvent *enh_dbg_notify_callback(void *unused, BxEvent *event) static size_t strip_whitespace(char *s) { size_t ptr = 0; - char *tmp = (char*)malloc(strlen(s)+1); + char *tmp = new [strlen(s)+1]; strcpy(tmp, s); while (s[ptr] == ' ') ptr++; if (ptr > 0) strcpy(s, tmp+ptr); - free(tmp); + delete [] tmp; ptr = strlen(s); while ((ptr > 0) && (s[ptr-1] == ' ')) { s[--ptr] = 0; diff --git a/bochs/osdep.cc b/bochs/osdep.cc index cab91e6bb..512961441 100644 --- a/bochs/osdep.cc +++ b/bochs/osdep.cc @@ -206,14 +206,12 @@ int main (int argc, char **argv) #if !BX_HAVE_STRDUP /* XXX use real strdup */ -char *bx_strdup(const char *str) +char *bx_strdup(const char *s) { - char *temp = (char*)malloc(strlen(str)+1); - sprintf(temp, "%s", str); - return temp; - - // Well, I'm sure this isn't how strdup is REALLY implemented, - // but it works... + char *p = malloc (strlen (s) + 1); // allocate memory + if (p != NULL) + strcpy (p,s); // copy string + return p; // return the memory } #endif /* !BX_HAVE_STRDUP */