by hcatlin · 13y ago · 0 comments
Aaron Leung and I have been working on this for a while. I'm the original creator of Sass and Aaron is a badass computer linguist. Hoping to announce some big new features around the end of the year.
Official site is at: http://libsass.org Or, follow us on Twitter for more updates: @hcatlin & @akhleung
Thanks for this!
char* copy_c_str(const char* orig)
{
size_t len = strlen(orig) + 1 ;
char* copy = (char*) malloc(sizeof(char) * len );
memcpy(copy, orig, len);
return copy;
}Anyway, please don't cast the return value of malloc() in C (http://stackoverflow.com/a/605858/28169).
Also, of course len should be const and sizeof (char) should be removed. Also testing whether malloc() succeeded before relying on the result being valid is a good idea (but perhaps there's machinery in place to abort on error), as is deciding what to do if the input string is NULL.
It's C++.
return( strdup( orig ) );
?