--- /dev/null
+diff -urN orig/frmts/jpeg2000/jpeg2000_vsil_io.cpp dwok/frmts/jpeg2000/jpeg2000_vsil_io.cpp
+--- orig/frmts/jpeg2000/jpeg2000_vsil_io.cpp 2016-01-26 16:21:48.000000000 +0100
++++ dwok/frmts/jpeg2000/jpeg2000_vsil_io.cpp 2016-11-16 21:53:15.280302723 +0100
+@@ -179,40 +179,25 @@
+ * Buffer initialization code.\r
+ \******************************************************************************/\r
+ \r
+-static void JPEG2000_VSIL_jas_stream_initbuf(jas_stream_t *stream, int bufmode, char *buf,\r
+- int bufsize)\r
++static void JPEG2000_VSIL_jas_stream_initbuf(jas_stream_t *stream, int bufmode)\r
+ {\r
+ /* If this function is being called, the buffer should not have been\r
+ initialized yet. */\r
+ assert(!stream->bufbase_);\r
+ \r
+ if (bufmode != JAS_STREAM_UNBUF) {\r
+- /* The full- or line-buffered mode is being employed. */\r
+- if (!buf) {\r
+- /* The caller has not specified a buffer to employ, so allocate\r
+- one. */\r
+- if ((stream->bufbase_ = (unsigned char*)jas_malloc(JAS_STREAM_BUFSIZE +\r
+- JAS_STREAM_MAXPUTBACK))) {\r
+- stream->bufmode_ |= JAS_STREAM_FREEBUF;\r
+- stream->bufsize_ = JAS_STREAM_BUFSIZE;\r
+- } else {\r
+- /* The buffer allocation has failed. Resort to unbuffered\r
+- operation. */\r
+- stream->bufbase_ = stream->tinybuf_;\r
+- stream->bufsize_ = 1;\r
+- }\r
++ if ((stream->bufbase_ = (unsigned char*)jas_malloc(JAS_STREAM_BUFSIZE +\r
++ JAS_STREAM_MAXPUTBACK))) {\r
++ stream->bufmode_ |= JAS_STREAM_FREEBUF;\r
++ stream->bufsize_ = JAS_STREAM_BUFSIZE;\r
+ } else {\r
+- /* The caller has specified a buffer to employ. */\r
+- /* The buffer must be large enough to accommodate maximum\r
+- putback. */\r
+- assert(bufsize > JAS_STREAM_MAXPUTBACK);\r
+- stream->bufbase_ = JAS_CAST(uchar *, buf);\r
+- stream->bufsize_ = bufsize - JAS_STREAM_MAXPUTBACK;\r
++ /* The buffer allocation has failed. Resort to unbuffered\r
++ operation. */\r
++ stream->bufbase_ = stream->tinybuf_;\r
++ stream->bufsize_ = 1;\r
+ }\r
+ } else {\r
+ /* The unbuffered mode is being employed. */\r
+- /* A buffer should not have been supplied by the caller. */\r
+- assert(!buf);\r
+ /* Use a trivial one-character buffer. */\r
+ stream->bufbase_ = stream->tinybuf_;\r
+ stream->bufsize_ = 1;\r
+@@ -282,7 +267,7 @@
+ }\r
+ \r
+ /* By default, use full buffering for this type of stream. */\r
+- JPEG2000_VSIL_jas_stream_initbuf(stream, JAS_STREAM_FULLBUF, 0, 0);\r
++ JPEG2000_VSIL_jas_stream_initbuf(stream, JAS_STREAM_FULLBUF);\r
+ \r
+ return stream;\r
+ }\r