summaryrefslogtreecommitdiff
path: root/src/ntriples_parse.c
diff options
context:
space:
mode:
authorDave Beckett <dave@dajobe.org>2013-12-05 13:40:53 -0800
committerDave Beckett <dave@dajobe.org>2013-12-05 13:40:53 -0800
commitc27498e6b8d1a995ecda8d01a30fbd239bc80961 (patch)
tree650556620015d5d73cc6d4fe92381a481078a63b /src/ntriples_parse.c
parent8a6b79436e5999400f9c850ba76f52e4df24854a (diff)
downloadraptor-c27498e6b8d1a995ecda8d01a30fbd239bc80961.tar.gz
Check N-Quads has 3/4 terms and N-Triples has 3
(raptor_ntriples_parse_line): Try to find 5th term and error out if it is.
Diffstat (limited to 'src/ntriples_parse.c')
-rw-r--r--src/ntriples_parse.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/ntriples_parse.c b/src/ntriples_parse.c
index 81740062..803d0840 100644
--- a/src/ntriples_parse.c
+++ b/src/ntriples_parse.c
@@ -166,7 +166,7 @@ raptor_ntriples_parse_line(raptor_parser* rdf_parser,
raptor_ntriples_parser_context *ntriples_parser = (raptor_ntriples_parser_context*)rdf_parser->context;
int i;
unsigned char *p;
- raptor_term* terms[MAX_NTRIPLES_TERMS] = {NULL, NULL, NULL, NULL};
+ raptor_term* terms[MAX_NTRIPLES_TERMS+1] = {NULL, NULL, NULL, NULL, NULL};
int rc = 0;
/* ASSERTION:
@@ -209,7 +209,7 @@ raptor_ntriples_parse_line(raptor_parser* rdf_parser,
/* Must be triple/quad */
- for(i = 0; i < 4; i++) {
+ for(i = 0; i < MAX_NTRIPLES_TERMS + 1; i++) {
if(!len) {
/* context is optional in nquads */
if (i == 3)
@@ -299,11 +299,25 @@ raptor_ntriples_parse_line(raptor_parser* rdf_parser,
}
- /* Check N-Triples has only 3 terms */
- if(!ntriples_parser->is_nquads) {
- if(terms[3]) {
- raptor_free_term(terms[3]);
- terms[3] = NULL;
+ if(ntriples_parser->is_nquads) {
+ /* Check N-Quads has 3 or 4 terms */
+ if(terms[4]) {
+ raptor_free_term(terms[4]);
+ terms[4] = NULL;
+ raptor_parser_error(rdf_parser, "N-Quads only allows 3 or 4 terms");
+ goto cleanup;
+ }
+ } else {
+ /* Check N-Triples has only 3 terms */
+ if(terms[3] || terms[4]) {
+ if(terms[4]) {
+ raptor_free_term(terms[4]);
+ terms[4] = NULL;
+ }
+ if(terms[3]) {
+ raptor_free_term(terms[3]);
+ terms[3] = NULL;
+ }
raptor_parser_error(rdf_parser, "N-Triples only allows 3 terms");
goto cleanup;
}