allocate buffer in +1 size

This commit is contained in:
Yuichi Nishiwaki 2014-06-25 17:22:15 +09:00
parent 08f0fbd3d3
commit b646948e9b
1 changed files with 6 additions and 5 deletions

View File

@ -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