$OpenBSD: patch-xvjpeg_c,v 1.2 2014/10/29 16:45:09 espie Exp $
--- xvjpeg.c.orig	Tue Oct 28 15:08:43 2014
+++ xvjpeg.c	Tue Oct 28 17:13:30 2014
@@ -315,6 +315,7 @@ static void doCmd(cmd)
 
 
 
+char errbuffer[JMSG_LENGTH_MAX];
 
 
 /*******************************************/
@@ -418,7 +419,7 @@ static void writeJPEG()
 
   if (pfree) free(inpix);
 
-  if (CloseOutFile(fp, filename, rv) == 0) DirBox(0);
+  if (CloseOutFileWhy(fp, filename, rv, errbuffer) == 0) DirBox(0);
   SetCursors(-1);
 }
 
@@ -444,7 +445,7 @@ METHODDEF void  xv_error_exit(cinfo)
   my_error_ptr myerr;
 
   myerr = (my_error_ptr) cinfo->err;
-  (*cinfo->err->output_message)(cinfo);     /* display error message */
+  (*cinfo->err->format_message)(cinfo, errbuffer);     /* fmt error message */
   longjmp(myerr->setjmp_buffer, 1);         /* return from error */
 }
 
@@ -696,7 +697,7 @@ L2:
         if ((cmy = *q++ - k) < 0) cmy = 0; *p++ = cmy; /* R */
         if ((cmy = *q++ - k) < 0) cmy = 0; *p++ = cmy; /* G */
         if ((cmy = *q++ - k) < 0) cmy = 0; *p++ = cmy; /* B */
-      } while (++q <= pic_end);
+      } while (++q < pic_end);
     }
     else { /* assume normal data */
       register byte *q = pic;
@@ -707,7 +708,7 @@ L2:
         if ((cmy = k - *q++) < 0) cmy = 0; *p++ = cmy; /* R */
         if ((cmy = k - *q++) < 0) cmy = 0; *p++ = cmy; /* G */
         if ((cmy = k - *q++) < 0) cmy = 0; *p++ = cmy; /* B */
-      } while (++q <= pic_end);
+      } while (++q < pic_end);
     }
     pic = realloc(pic,p-pic); /* Release extra storage */
   }
@@ -851,7 +852,11 @@ METHODDEF boolean  xv_process_app1(cinfo)
     exifInfo = (byte *) malloc((size_t) length);
     exifInfoSize = 0;
   }
-  else exifInfo = (byte *) realloc(exifInfo, exifInfoSize + length);
+  else {
+  	/* one APP1 data struct only, ignore extra stuff */
+        while (length-- > 0)
+		(void)j_getc(cinfo);
+  }
   if (!exifInfo) FatalError("out of memory in xv_process_app1 (EXIF info)");
   
   sp = exifInfo + exifInfoSize;
