aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-08-05 22:00:40 +0000
committerDavid Robillard <d@drobilla.net>2014-08-05 22:00:40 +0000
commit5a132332a6b00417d2f954939cbafeacdcd0c0ac (patch)
treedc6ed18e4b6ce322b2126d88d336e80c47c8c433
parentcb9ee287d9c99be0b552291355abf11379060a67 (diff)
downloadserd-5a132332a6b00417d2f954939cbafeacdcd0c0ac.tar.gz
serd-5a132332a6b00417d2f954939cbafeacdcd0c0ac.tar.bz2
serd-5a132332a6b00417d2f954939cbafeacdcd0c0ac.zip
Fix const-correctness violation for reader input string.
git-svn-id: http://svn.drobilla.net/serd/trunk@465 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--NEWS3
-rw-r--r--src/reader.c25
2 files changed, 16 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 096995c7..99e9b735 100644
--- a/NEWS
+++ b/NEWS
@@ -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;
diff --git a/src/reader.c b/src/reader.c
index 664cb361..f85e9f7b 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -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
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,
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,
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
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)
{
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;