diff --git a/src/marc_read_line.c b/src/marc_read_line.c index 7bfa1983..000e8186 100644 --- a/src/marc_read_line.c +++ b/src/marc_read_line.c @@ -201,13 +201,14 @@ int yaz_marc_read_line(yaz_marc_t mt, next = cp; while ((next = strchr(next, marker_ch))) { + /* allow only alphanumeric characters */ if ((next[1] >= 'A' && next[1] <= 'Z') ||(next[1] >= 'a' && next[1] <= 'z') ||(next[1] >= '0' && next[1] <= '9')) { if (!marker_skip) break; - else if (next[2] == ' ') + else if (next[-1] == ' ') break; } next++; @@ -216,20 +217,13 @@ int yaz_marc_read_line(yaz_marc_t mt, if (next) len = next - cp - marker_skip; - if (marker_skip) + if (marker_skip && len > 1 && cp[1] == ' ') { /* remove ' ' after subfield marker */ - char *cp_blank = strchr(cp, ' '); - if (cp_blank) - { - len--; - while (cp_blank != cp) - { - cp_blank[0] = cp_blank[-1]; - cp_blank--; - } - cp++; - } + char *cp_mod = (char *) cp; /* line is allocated locally, so we can modify it */ + cp_mod[1] = cp_mod[0]; /* does not deal with multi-byte subfields */ + len--; + cp++; } yaz_marc_add_subfield(mt, cp, len); if (!next) diff --git a/src/retrieval.c b/src/retrieval.c index 79358005..abecbe54 100644 --- a/src/retrieval.c +++ b/src/retrieval.c @@ -318,7 +318,7 @@ int yaz_retrieval_request(yaz_retrieval_t p, schema_ok = 1; else { - char *cp = 0; + const char *cp = 0; wrbuf_rewind(w); if (el->split && *el->split && (cp = strchr(schema, *el->split))) wrbuf_write(w, schema, cp - schema); @@ -361,7 +361,7 @@ int yaz_retrieval_request(yaz_retrieval_t p, { if (*el->backend_name) { - char *cp; + const char *cp; wrbuf_rewind(w); wrbuf_puts(w, el->backend_name); if (el->split && *el->split && schema diff --git a/src/solr.c b/src/solr.c index 93f00587..1e5614f1 100644 --- a/src/solr.c +++ b/src/solr.c @@ -261,7 +261,7 @@ static int yaz_solr_decode_scan_result(ODR o, xmlNodePtr ptr, Z_SRW_scanResponse *scr) { xmlNodePtr node; - char *pos; + const char *pos; int i = 0; /* find the actual list */ @@ -297,19 +297,17 @@ static int yaz_solr_decode_scan_result(ODR o, xmlNodePtr ptr, * This is due to SOLR not being able to encode them into 2 separate attributes. */ pos = strchr(val, '^'); - if (pos != NULL) + if (pos) { term->displayTerm = odr_strdup(o, pos + 1); - *pos = '\0'; - term->value = odr_strdup(o, val); - *pos = '^'; + term->value = odr_strdupn(o, val, pos - val); } else { term->value = odr_strdup(o, val); - term->displayTerm = NULL; + term->displayTerm = 0; } - term->whereInList = NULL; + term->whereInList = 0; i++; } } diff --git a/src/zoom-record-cache.c b/src/zoom-record-cache.c index 957e8f91..d83006f1 100644 --- a/src/zoom-record-cache.c +++ b/src/zoom-record-cache.c @@ -109,10 +109,11 @@ static ZOOM_record record_cache_add(ZOOM_resultset r, { if (diag->uri) { - char *cp; - rc->rec.diag_set = odr_strdup(r->odr, diag->uri); - if ((cp = strrchr(rc->rec.diag_set, '/'))) - *cp = '\0'; + const char *cp = strrchr(diag->uri, '/'); + if (cp) + rc->rec.diag_set = odr_strdupn(r->odr, diag->uri, cp - diag->uri); + else + rc->rec.diag_set = odr_strdup(r->odr, diag->uri); rc->rec.diag_uri = odr_strdup(r->odr, diag->uri); } rc->rec.diag_message = odr_strdup_null(r->odr, diag->message); diff --git a/test/test_marc_read_sax.c b/test/test_marc_read_sax.c index 7f335ce8..90029a6f 100644 --- a/test/test_marc_read_sax.c +++ b/test/test_marc_read_sax.c @@ -41,8 +41,16 @@ static void tst1(void) yaz_marc_t mt = yaz_marc_create(); yaz_marc_sax_t yt = yaz_marc_sax_new(mt, handler, &user_data); xmlSAXHandlerPtr sax_ptr = yaz_marc_sax_get_handler(yt); + xmlParserCtxtPtr parser_ctxt = xmlCreatePushParserCtxt(sax_ptr, yt, + marcxml, + strlen(marcxml), 0); - xmlSAXUserParseMemory(sax_ptr, yt, marcxml, strlen(marcxml)); + YAZ_CHECK(parser_ctxt); + if (parser_ctxt) + { + YAZ_CHECK_EQ(xmlParseChunk(parser_ctxt, 0, 0, 1), 0); + xmlFreeParserCtxt(parser_ctxt); + } const char *expect = "\n" " 00062cgm a2200037Ia 4500\n" diff --git a/test/test_tpath.c b/test/test_tpath.c index d199aadb..265df978 100644 --- a/test/test_tpath.c +++ b/test/test_tpath.c @@ -2,15 +2,14 @@ * Copyright (C) Index Data * See the file LICENSE for details. */ -#include -#include -#include -#include - #if HAVE_CONFIG_H #include #endif +#include +#include +#include +#include static void tst_tpath(void) {