Jump to content

Safely remove malloc in SystemC


sumit_tuwien

Recommended Posts

We have discovered C-style dynamic memory allocation in following files:

 


   utils/sc_report.cpp
   utils/sc_hash.cpp
   utils/sc_report_handler.cpp
   utils/sc_mempool.cpp

 

 

However, dynamic memory allocation for other C++ files have been done using C++ style new/delete.
 
Our question: Can we replace them safely with new/delete or we will see some surprises ?
 
In fact it seems they are legacy codes taken from somewhere and we can replace them safely. Example (utils/sc_report.cpp)
 
 

 

............
............
static char empty_str[] = "";
static inline char * empty_dup(const char * p)
{
    if ( p && *p )
    {
        char* result;
        result = (char*)malloc(strlen(p)+1); // Very very legacy C style
        strcpy(result, p);
        return result;
    }
    else
    {
        return empty_str;
    }
}


............
............

 

 

 
Regards, Sumit
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...