Browse Source

Fix const-correctness violation for reader input string.

git-svn-id: http://svn.drobilla.net/serd/trunk@465 490d8e77-9747-427b-9fa3-0b8f29cee8a0
zrythm_meson
David Robillard 8 years ago
parent
commit
5a132332a6
  1. 3
      NEWS
  2. 25
      src/reader.c

3
NEWS

@ -6,10 +6,11 @@ serd (0.18.3) unstable; @@ -6,10 +6,11 @@ serd (0.18.3) unstable;
* Fix possible crash in serd_writer_end_anon() when writing invalid lists
* Generate blank names like _:b1 and _:B2 not _:genid1 _:docid2
* Correctly handle posix_memalign failure
* Fix const-correctness violation for reader input string
* Add -lm to pkg-config libs
* Update to waf 1.7.14
-- David Robillard <d@drobilla.net> Tue, 24 Dec 2013 23:30:22 -0500
-- David Robillard <d@drobilla.net> Tue, 05 Aug 2014 17:59:30 -0400
serd (0.18.2) stable;

25
src/reader.c

@ -78,7 +78,8 @@ struct SerdReaderImpl { @@ -78,7 +78,8 @@ struct SerdReaderImpl {
uint8_t* bprefix;
size_t bprefix_len;
unsigned next_id;
uint8_t* read_buf;
const uint8_t* read_buf;
uint8_t* file_buf;
int32_t read_head; ///< Offset into read_buf
uint8_t read_byte; ///< 1-byte 'buffer' used when not paging
bool from_file; ///< True iff reading from @ref fd
@ -108,13 +109,13 @@ static inline SerdStatus @@ -108,13 +109,13 @@ static inline SerdStatus
page(SerdReader* reader)
{
reader->read_head = 0;
size_t n_read = fread(reader->read_buf, 1, SERD_PAGE_SIZE, reader->fd);
size_t n_read = fread(reader->file_buf, 1, SERD_PAGE_SIZE, reader->fd);
if (n_read == 0) {
reader->read_buf[0] = '\0';
reader->eof = true;
reader->file_buf[0] = '\0';
reader->eof = true;
return ferror(reader->fd) ? SERD_ERR_UNKNOWN : SERD_FAILURE;
} else if (n_read < SERD_PAGE_SIZE) {
reader->read_buf[n_read] = '\0';
reader->file_buf[n_read] = '\0';
}
return SERD_SUCCESS;
}
@ -1463,6 +1464,7 @@ serd_reader_new(SerdSyntax syntax, @@ -1463,6 +1464,7 @@ serd_reader_new(SerdSyntax syntax,
me->bprefix_len = 0;
me->next_id = 1;
me->read_buf = 0;
me->file_buf = 0;
me->read_head = 0;
me->eof = false;
me->seen_genid = false;
@ -1584,8 +1586,9 @@ serd_reader_start_stream(SerdReader* me, @@ -1584,8 +1586,9 @@ serd_reader_start_stream(SerdReader* me,
me->paging = bulk;
if (bulk) {
me->read_buf = (uint8_t*)serd_bufalloc(SERD_PAGE_SIZE);
memset(me->read_buf, '\0', SERD_PAGE_SIZE);
me->file_buf = (uint8_t*)serd_bufalloc(SERD_PAGE_SIZE);
me->read_buf = me->file_buf;
memset(me->file_buf, '\0', SERD_PAGE_SIZE);
SerdStatus st = page(me);
if (st) {
serd_reader_end_stream(me);
@ -1621,10 +1624,10 @@ SerdStatus @@ -1621,10 +1624,10 @@ SerdStatus
serd_reader_end_stream(SerdReader* me)
{
if (me->paging) {
free(me->read_buf);
free(me->file_buf);
}
me->fd = 0;
me->read_buf = NULL;
me->fd = NULL;
me->read_buf = me->file_buf = NULL;
return SERD_SUCCESS;
}
@ -1646,7 +1649,7 @@ serd_reader_read_string(SerdReader* me, const uint8_t* utf8) @@ -1646,7 +1649,7 @@ serd_reader_read_string(SerdReader* me, const uint8_t* utf8)
{
const Cursor cur = { (const uint8_t*)"(string)", 1, 1 };
me->read_buf = (uint8_t*)utf8;
me->read_buf = utf8;
me->read_head = 0;
me->cur = cur;
me->from_file = false;

Loading…
Cancel
Save