From b646948e9b67be73cc201d1056de8eaf414110ed Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 25 Jun 2014 17:22:15 +0900 Subject: [PATCH] allocate buffer in +1 size --- src/port.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/port.c b/src/port.c index 6febdf8e..168b5cce 100644 --- a/src/port.c +++ b/src/port.c @@ -87,19 +87,20 @@ pic_open_output_string(pic_state *pic) struct pic_string * pic_get_output_string(pic_state *pic, struct pic_port *port) { - long endpos; + long size; char *buf; /* get endpos */ xfflush(port->file); - endpos = xftell(port->file); + size = xftell(port->file); xrewind(port->file); /* copy to buf */ - buf = (char *)pic_alloc(pic, endpos); - xfread(buf, 1, endpos, port->file); + buf = (char *)pic_alloc(pic, size + 1); + buf[size] = 0; + xfread(buf, size, 1, port->file); - return pic_str_new(pic, buf, endpos); + return pic_str_new(pic, buf, size); } void