c++ better to use new/delete and not malloc
This commit is contained in:
parent
0059d33102
commit
98c69ce6ae
@ -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;
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user