Reading strings with the READ instruction when the NullTerminatedString property is set now works correctly on all streams.

[INTERPRETER]
* BUG: Reading strings with the READ instruction when the NullTerminatedString property is set now works correctly on all streams.
This commit is contained in:
gambas 2019-12-20 00:29:07 +01:00
parent 4771af3b27
commit 64be06797e

View file

@ -1229,12 +1229,19 @@ void STREAM_read_type(STREAM *stream, TYPE type, VALUE *value)
case T_STRING: case T_STRING:
if (stream->common.null_terminated) if (stream->common.null_terminated)
{
if (stream->type == &STREAM_memory)
{ {
ssize_t slen; ssize_t slen;
if (CHECK_strlen(stream->memory.addr + stream->memory.pos, &slen)) if (CHECK_strlen(stream->memory.addr + stream->memory.pos, &slen))
THROW(E_READ); THROW(E_READ);
len = (int)slen; len = (int)slen;
} }
else
{
len = -1;
}
}
else else
len = read_length(stream); len = read_length(stream);
@ -1243,6 +1250,24 @@ void STREAM_read_type(STREAM *stream, TYPE type, VALUE *value)
STRING_new_temp_value(value, NULL, len); STRING_new_temp_value(value, NULL, len);
STREAM_read(stream, value->_string.addr, len); STREAM_read(stream, value->_string.addr, len);
} }
else if (len < 0)
{
char *str = NULL;
for(len = 0;; len++)
{
STREAM_read(stream, &buffer._byte, 1);
if (buffer._byte == 0)
break;
str = STRING_add_char(str, buffer._byte);
}
STRING_free_later(str);
value->_string.addr = str;
value->_string.len = len;
value->_string.start = 0;
value->type = T_STRING;
}
else else
{ {
STRING_void_value(value); STRING_void_value(value);