pic_str_new may take a NULL ptr

This commit is contained in:
Yuichi Nishiwaki 2014-02-09 03:11:08 +09:00
parent 668ace7901
commit 49e5e3085b
1 changed files with 8 additions and 1 deletions

View File

@ -10,10 +10,17 @@ struct pic_string *
pic_str_new(pic_state *pic, const char *cstr, size_t len)
{
struct pic_string *str;
char *copy;
if (cstr) {
copy = pic_strdup(pic, cstr);
} else {
copy = (char *)pic_alloc(pic, len);
}
str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING);
str->len = len;
str->str = pic_strdup(pic, cstr);
str->str = copy;
return str;
}