From 73d9b0dc79c2c191a10fbb1a1d16a27b609cf13c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 15 Nov 2013 17:08:18 +0900 Subject: [PATCH] use strndup if possible --- src/string.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/string.c b/src/string.c index 09806b25..9f0ce59a 100644 --- a/src/string.c +++ b/src/string.c @@ -6,15 +6,10 @@ pic_value pic_str_new(pic_state *pic, const char *cstr, size_t len) { 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->len = len; - str->str = new_str; + str->str = strdup(cstr); return pic_obj_value(str); }