Ticket #12662: 0001-Declare-certain-variables-as-volaile-to-silence-long.patch

File 0001-Declare-certain-variables-as-volaile-to-silence-long.patch, 6.0 KB (added by MichaelCrawford, 8 years ago)

Silenced warnings in PNGTranslator.cpp, enabled -Werror in ArchitectureRules

  • build/jam/ArchitectureRules

    From 40e6efddbc77a3eb9a496400c3e01a418441fb3a Mon Sep 17 00:00:00 2001
    From: Michael Crawford <mdcrawford@gmail.com>
    Date: Thu, 25 Feb 2016 10:08:59 -0800
    Subject: [PATCH] Declare certain variables as volaile to silence longjmp
     warnings.
    
    ---
     build/jam/ArchitectureRules                   |  2 +-
     src/add-ons/translators/png/PNGTranslator.cpp | 43 ++++++++++++++++-----------
     2 files changed, 26 insertions(+), 19 deletions(-)
    
    diff --git a/build/jam/ArchitectureRules b/build/jam/ArchitectureRules
    index 93d284a..c4c9675 100644
    a b rule ArchitectureSetupWarnings architecture  
    612612    EnableWerror src add-ons translators jpeg ; # gcc2
    613613    EnableWerror src add-ons translators jpeg2000 ;
    614614    EnableWerror src add-ons translators pcx ;
    615 #   EnableWerror src add-ons translators png ; # gcc2
     615    EnableWerror src add-ons translators png ; # gcc2
    616616    EnableWerror src add-ons translators ppm ;
    617617    EnableWerror src add-ons translators raw ;
    618618    EnableWerror src add-ons translators rtf ;
  • src/add-ons/translators/png/PNGTranslator.cpp

    diff --git a/src/add-ons/translators/png/PNGTranslator.cpp b/src/add-ons/translators/png/PNGTranslator.cpp
    index a982ad3..1d30755 100644
    a b pngcb_flush_data(png_structp ppng)  
    193193// Returns:
    194194// ---------------------------------------------------------------
    195195PNGTranslator::PNGTranslator()
    196     : BaseTranslator(B_TRANSLATE("PNG images"), 
     196    : BaseTranslator(B_TRANSLATE("PNG images"),
    197197        B_TRANSLATE("PNG image translator"),
    198198        PNG_TRANSLATOR_VERSION,
    199199        sInputFormats, kNumInputFormats,
    PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,  
    299299    if (identify_png_header(inSource, NULL) != B_OK)
    300300        return B_NO_TRANSLATOR;
    301301
    302     status_t result = B_ERROR;
     302    volatile status_t result = B_ERROR;
    303303        // if a libpng errors before this is set
    304304        // to a different value, the above is what
    305305        // will be returned from this function
    PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,  
    307307    bool bheaderonly = false, bdataonly = false;
    308308
    309309    // for storing decoded PNG row data
    310     uint8 **prows = NULL, *prow = NULL;
    311     png_uint_32 nalloc = 0;
     310    uint8 ** volatile prows = NULL, * volatile prow = NULL;
     311    volatile png_uint_32 nalloc = 0;
    312312
    313313    png_structp ppng = NULL;
    314314    png_infop pinfo = NULL;
    PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,  
    424424                break;
    425425            }
    426426            for (png_uint_32 i = 0; i < height; i++) {
    427                 png_read_row(ppng, prow, NULL);
    428                 outDestination->Write(prow, width * kbytes);
     427                // prow was declared volatile to silence warning about
     428                // being clobbered by longjmp
     429                png_read_row(ppng, const_cast<uint8*>(prow), NULL);
     430                outDestination->Write(const_cast<uint8*>(prow),
     431                                        width * kbytes);
    429432            }
    430433            result = B_OK;
    431434                // Set OK status here, because, in the event of
    PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,  
    440443
    441444        } else {
    442445            // interlaced PNG image
    443             prows = new uint8 *[height];
     446            // prows = new uint8 *[height];
     447            prows = static_cast<uint8 ** volatile>(new uint8 *[height]);
    444448            if (!prows) {
    445449                result = B_NO_MEMORY;
    446450                break;
    PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,  
    455459            if (nalloc < height)
    456460                result = B_NO_MEMORY;
    457461            else {
    458                 png_read_image(ppng, prows);
     462                png_read_image(ppng, const_cast<uint8**>(prows));
    459463
    460464                for (png_uint_32 i = 0; i < height; i++)
    461                     outDestination->Write(prows[i], width * kbytes);
     465                    outDestination->Write(const_cast<uint8*>(prows[i]),
     466                                            width * kbytes);
    462467                result = B_OK;
    463468                    // Set OK status here, because, in the event of
    464469                    // an error, png_read_end() will longjmp to error
    PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,  
    717722    if (result != B_OK)
    718723        return result;
    719724
    720     const color_map *pmap = NULL;
     725    const color_map * volatile pmap = NULL;
    721726    if (bitsHeader.colors == B_CMAP8) {
    722727        pmap = system_colors();
    723728        if (!pmap)
    PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,  
    728733    width = static_cast<png_uint_32>(bitsHeader.bounds.Width() + 1);
    729734    height = static_cast<png_uint_32>(bitsHeader.bounds.Height() + 1);
    730735
    731     int32 pngBytesPerPixel = 0;
    732     int bit_depth, color_type, interlace_type;
     736    volatile int32 pngBytesPerPixel = 0;
     737    int bit_depth, interlace_type;
     738    volatile int color_type;
    733739    bit_depth = 8;
    734740    switch (bitsHeader.colors) {
    735741        case B_RGBA32:
    PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,  
    768774    }
    769775    interlace_type = fSettings->SetGetInt32(PNG_SETTING_INTERLACE);
    770776
    771     int32 bitsBytesPerPixel = 0;
     777    volatile int32 bitsBytesPerPixel = 0;
    772778    switch (bitsHeader.colors) {
    773779        case B_RGBA32:
    774780        case B_RGBA32_BIG:
    PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,  
    804810            return B_NO_TRANSLATOR;
    805811    };
    806812
    807     uint8 *pbitsrow = NULL, *prow = NULL;
     813    uint8 * volatile pbitsrow = NULL, * volatile prow = NULL;
    808814        // row buffers
    809815    // image buffer for writing whole png image at once
    810     uint8 **prows = NULL;
    811     png_uint_32 nalloc = 0;
     816    uint8 ** volatile prows = NULL;
     817    volatile png_uint_32 nalloc = 0;
    812818
    813819    png_structp ppng = NULL;
    814820    png_infop pinfo = NULL;
    PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,  
    886892            for (png_uint_32 i = 0; i < height; i++) {
    887893                inSource->Read(pbitsrow, bitsHeader.rowBytes);
    888894
     895                // We're casting away pmap's virtualness, not its constness
    889896                pix_bits_to_png(pbitsrow, prow, bitsHeader.colors, width,
    890                     pmap, bitsBytesPerPixel);
     897                    const_cast<color_map*>(pmap), bitsBytesPerPixel);
    891898
    892899                png_write_row(ppng, prow);
    893900            }
    BView *  
    985992PNGTranslator::NewConfigView(TranslatorSettings *settings)
    986993{
    987994    return new PNGView(BRect(0, 0, PNG_VIEW_WIDTH, PNG_VIEW_HEIGHT),
    988         B_TRANSLATE("PNGTranslator Settings"), B_FOLLOW_ALL, 
     995        B_TRANSLATE("PNGTranslator Settings"), B_FOLLOW_ALL,
    989996        B_WILL_DRAW, settings);
    990997}
    991998