Fix uninit variable (hits_limit)
[idzebra-moved-to-github.git] / index / zebrasrv.c
index 75fabaa..999e915 100644 (file)
@@ -17,6 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,6 +37,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/log.h>
 #include <yaz/ill.h>
 #include <yaz/yaz-util.h>
+#include <yaz/yaz-version.h>
 #include <yaz/diagbib1.h>
 #include <yaz/querytowrbuf.h>
 #include <yaz/pquery.h>
@@ -271,13 +275,15 @@ static int break_handler(void *client_data)
 static Z_RPNQuery *query_add_sortkeys(ODR o, Z_RPNQuery *query,
                                       const char *sortKeys)
 {
+#if YAZ_VERSIONL >= 0x40200
     /* sortkey layour: path,schema,ascending,caseSensitive,missingValue */
     /* see cql_sortby_to_sortkeys of YAZ. */
     char **sortspec;
-    int num_sortspec;
+    int num_sortspec = 0;
     int i;
 
-    nmem_strsplit_blank(odr_getmem(o), sortKeys, &sortspec, &num_sortspec);
+    if (sortKeys)
+        nmem_strsplit_blank(odr_getmem(o), sortKeys, &sortspec, &num_sortspec);
     if (num_sortspec > 0)
     {
         Z_RPNQuery *nquery;
@@ -292,13 +298,13 @@ static Z_RPNQuery *query_add_sortkeys(ODR o, Z_RPNQuery *query,
             int ascending = 1;
             nmem_strsplitx(odr_getmem(o), ",", sortspec[i], &arg, &num_arg, 0);
             
-            if (num_arg != 5)
+            if (num_arg > 5 || num_arg < 1)
             {
                 yaz_log(YLOG_WARN, "Invalid sort spec '%s' num_arg=%d",
                         sortspec[i], num_arg);
                 break;
             }
-            if (arg[2][0])
+            if (num_arg > 2 && arg[2][0])
                 ascending = atoi(arg[2]);
             
             if (i < num_sortspec-1)
@@ -331,6 +337,12 @@ static Z_RPNQuery *query_add_sortkeys(ODR o, Z_RPNQuery *query,
         }
         wrbuf_destroy(w);
     }
+#else
+    if (sortKeys)
+    {
+        yaz_log(YLOG_WARN, "sortkeys ignored because YAZ version < 4.2.0");
+    }
+#endif
     return query;
 }