Build failure due to const cast

Issue #135 resolved
Carmelo DrRaw created an issue

My automated AppImage packages are failing due to the following build error:

/sources/rtengine/imageio.cc: In member function ‘int rtengine::ImageIO::loadJPEGFromMemory(const char*, int)’:
/sources/rtengine/imageio.cc:377:26: error: invalid conversion from ‘const unsigned char*’ to ‘unsigned char*’ [-fpermissive]
     jpeg_mem_src(&cinfo, reinterpret_cast<const unsigned char *>(buffer), bufsize);
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /sources/rtengine/iccjpeg.h:20:0,
                 from /sources/rtengine/imageio.cc:41:
/usr/include/jpeglib.h:1008:14: note:   initializing argument 2 of ‘void jpeg_mem_src(j_decompress_ptr, unsigned char*, long unsigned int)’
 EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,

It seems there is an unnecessary cast to const unsigned char *

Comments (5)

  1. Carmelo DrRaw reporter

    I am using libjpeg-turbo 1.2.90-8, which is the package provided by the CentOS 7 repositories.

  2. agriggio repo owner

    does this patch work for you?

    diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc
    --- a/rtengine/imageio.cc
    +++ b/rtengine/imageio.cc
    @@ -374,7 +374,7 @@
         jpeg_decompress_struct cinfo;
         jpeg_create_decompress(&cinfo);
         //rt_jpeg_memory_src (&cinfo, (const JOCTET*)buffer, bufsize);
    -    jpeg_mem_src(&cinfo, reinterpret_cast<const unsigned char *>(buffer), bufsize);
    +    jpeg_mem_src(&cinfo, const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(buffer)), bufsize);
    
         /* We use our private extension JPEG error handler.
            Note that this struct must live as long as the main JPEG parameter
    

  3. Log in to comment