Tidy up opj_ callback functions in fx_codec_jpx_obj.cpp

This is code cleanup rather than bug fixing.

The motivation for this was to fix the casts at line 97 of the original file.  These are wrong; you cannot correct via casting a function signature mismatch when passing a function as an argument.  In theory, there's no reason to believe that the compiler will pass args in the same manner for a function of type (void*, size_t, void*) as for a function of type (void*, size_t, some_struct*).  The cast will suppress the compile error, but you can't be assured the call will work as intended.  In practice, it does, since the last architecture where a void* had a different representation than a struct* went extinct in the late 80s.

In the functions themselves, note that we currently bail out if srcData->offset >= srcData->src_size, so the expression
   bufferLength = (OPJ_SIZE_T)(srcData->src_size - srcData->offset)

will always be > 0.  Hence the check
   if(bufferLength <= 0)
is pointless, esp. since bufferLength is a signed type and < 0 makes no sense.

The opj_seek_from_memory() has a bool return value, so returning -1 on error doesn't seem reasonable.  Change this to TRUE/FALSE, and return false on seek past end.

If we're truly passing readonly data, then perhaps it makes sense to make the write() function always return -1. I didn't do this.

Lastly, I capitalize "DecodeData" so that it looks like a struct, and change its members to be size_t's to avoid casting back and forth.

R=jun_fang@foxitsoftware.com

Review URL: https://codereview.chromium.org/507273003
1 file changed