allocate buffer in +1 size
This commit is contained in:
parent
08f0fbd3d3
commit
b646948e9b
11
src/port.c
11
src/port.c
|
@ -87,19 +87,20 @@ pic_open_output_string(pic_state *pic)
|
||||||
struct pic_string *
|
struct pic_string *
|
||||||
pic_get_output_string(pic_state *pic, struct pic_port *port)
|
pic_get_output_string(pic_state *pic, struct pic_port *port)
|
||||||
{
|
{
|
||||||
long endpos;
|
long size;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
/* get endpos */
|
/* get endpos */
|
||||||
xfflush(port->file);
|
xfflush(port->file);
|
||||||
endpos = xftell(port->file);
|
size = xftell(port->file);
|
||||||
xrewind(port->file);
|
xrewind(port->file);
|
||||||
|
|
||||||
/* copy to buf */
|
/* copy to buf */
|
||||||
buf = (char *)pic_alloc(pic, endpos);
|
buf = (char *)pic_alloc(pic, size + 1);
|
||||||
xfread(buf, 1, endpos, port->file);
|
buf[size] = 0;
|
||||||
|
xfread(buf, size, 1, port->file);
|
||||||
|
|
||||||
return pic_str_new(pic, buf, endpos);
|
return pic_str_new(pic, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue