use strndup if possible
This commit is contained in:
parent
754d53443b
commit
73d9b0dc79
|
@ -6,15 +6,10 @@ pic_value
|
||||||
pic_str_new(pic_state *pic, const char *cstr, size_t len)
|
pic_str_new(pic_state *pic, const char *cstr, size_t len)
|
||||||
{
|
{
|
||||||
struct pic_string *str;
|
struct pic_string *str;
|
||||||
char *new_str;
|
|
||||||
|
|
||||||
new_str = (char *)pic_alloc(pic, len + 1);
|
|
||||||
strncpy(new_str, cstr, len);
|
|
||||||
new_str[len] = '\0';
|
|
||||||
|
|
||||||
str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING);
|
str = (struct pic_string *)pic_obj_alloc(pic, sizeof(struct pic_string), PIC_TT_STRING);
|
||||||
str->len = len;
|
str->len = len;
|
||||||
str->str = new_str;
|
str->str = strdup(cstr);
|
||||||
|
|
||||||
return pic_obj_value(str);
|
return pic_obj_value(str);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue