Simplify in a lot of places using odr_strdupn
[yaz-moved-to-github.git] / src / uri.c
index 6db68e5..fae1411 100644 (file)
--- a/src/uri.c
+++ b/src/uri.c
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -132,7 +132,7 @@ int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val)
     {
         cp++;
         no++;
-        while (*cp != '=')
+        while (*cp && *cp != '=' && *cp != '&')
         {
             /* check that x-form names looks sane */
             if (*cp <= ' ' || *cp >= 127)
@@ -153,10 +153,7 @@ int yaz_uri_to_array(const char *path, ODR o, char ***name, char ***val)
         for (cp = path; *cp && *cp != '=' && *cp != '&'; cp++)
             ;
 
-        (*name)[no] = (char *) odr_malloc(o, (cp-path)+1);
-        memcpy((*name)[no], path, cp-path);
-        (*name)[no][cp-path] = '\0';
-
+        (*name)[no] = odr_strdupn(o, path, cp - path);
         path = cp;
         if (*path == '=')
         {