$OpenBSD: patch-k2pdfoptlib_textrows_c,v 1.1.1.1 2017/08/18 12:07:51 pirofti Exp $

Index: k2pdfoptlib/textrows.c
--- k2pdfoptlib/textrows.c.orig
+++ k2pdfoptlib/textrows.c
@@ -956,6 +956,11 @@ static int maxval(int *x,int n,int n0,int dx,int *inde
         if (imax<0 || x[i]>x[imax])
             imax=i;
         }
+    if (imax < 0) 	/* handle negative index by returning the first entry */
+        if (index)
+	    (*index)=0;
+        return(x[0]);
+
     if (index!=NULL)
         (*index)=imax+n0;
     return(x[imax]);
