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
|
612 | 612 | EnableWerror src add-ons translators jpeg ; # gcc2 |
613 | 613 | EnableWerror src add-ons translators jpeg2000 ; |
614 | 614 | EnableWerror src add-ons translators pcx ; |
615 | | # EnableWerror src add-ons translators png ; # gcc2 |
| 615 | EnableWerror src add-ons translators png ; # gcc2 |
616 | 616 | EnableWerror src add-ons translators ppm ; |
617 | 617 | EnableWerror src add-ons translators raw ; |
618 | 618 | EnableWerror src add-ons translators rtf ; |
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)
|
193 | 193 | // Returns: |
194 | 194 | // --------------------------------------------------------------- |
195 | 195 | PNGTranslator::PNGTranslator() |
196 | | : BaseTranslator(B_TRANSLATE("PNG images"), |
| 196 | : BaseTranslator(B_TRANSLATE("PNG images"), |
197 | 197 | B_TRANSLATE("PNG image translator"), |
198 | 198 | PNG_TRANSLATOR_VERSION, |
199 | 199 | sInputFormats, kNumInputFormats, |
… |
… |
PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
299 | 299 | if (identify_png_header(inSource, NULL) != B_OK) |
300 | 300 | return B_NO_TRANSLATOR; |
301 | 301 | |
302 | | status_t result = B_ERROR; |
| 302 | volatile status_t result = B_ERROR; |
303 | 303 | // if a libpng errors before this is set |
304 | 304 | // to a different value, the above is what |
305 | 305 | // will be returned from this function |
… |
… |
PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
307 | 307 | bool bheaderonly = false, bdataonly = false; |
308 | 308 | |
309 | 309 | // 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; |
312 | 312 | |
313 | 313 | png_structp ppng = NULL; |
314 | 314 | png_infop pinfo = NULL; |
… |
… |
PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
424 | 424 | break; |
425 | 425 | } |
426 | 426 | 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); |
429 | 432 | } |
430 | 433 | result = B_OK; |
431 | 434 | // Set OK status here, because, in the event of |
… |
… |
PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
440 | 443 | |
441 | 444 | } else { |
442 | 445 | // interlaced PNG image |
443 | | prows = new uint8 *[height]; |
| 446 | // prows = new uint8 *[height]; |
| 447 | prows = static_cast<uint8 ** volatile>(new uint8 *[height]); |
444 | 448 | if (!prows) { |
445 | 449 | result = B_NO_MEMORY; |
446 | 450 | break; |
… |
… |
PNGTranslator::translate_from_png_to_bits(BPositionIO *inSource,
|
455 | 459 | if (nalloc < height) |
456 | 460 | result = B_NO_MEMORY; |
457 | 461 | else { |
458 | | png_read_image(ppng, prows); |
| 462 | png_read_image(ppng, const_cast<uint8**>(prows)); |
459 | 463 | |
460 | 464 | 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); |
462 | 467 | result = B_OK; |
463 | 468 | // Set OK status here, because, in the event of |
464 | 469 | // an error, png_read_end() will longjmp to error |
… |
… |
PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
717 | 722 | if (result != B_OK) |
718 | 723 | return result; |
719 | 724 | |
720 | | const color_map *pmap = NULL; |
| 725 | const color_map * volatile pmap = NULL; |
721 | 726 | if (bitsHeader.colors == B_CMAP8) { |
722 | 727 | pmap = system_colors(); |
723 | 728 | if (!pmap) |
… |
… |
PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
728 | 733 | width = static_cast<png_uint_32>(bitsHeader.bounds.Width() + 1); |
729 | 734 | height = static_cast<png_uint_32>(bitsHeader.bounds.Height() + 1); |
730 | 735 | |
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; |
733 | 739 | bit_depth = 8; |
734 | 740 | switch (bitsHeader.colors) { |
735 | 741 | case B_RGBA32: |
… |
… |
PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
768 | 774 | } |
769 | 775 | interlace_type = fSettings->SetGetInt32(PNG_SETTING_INTERLACE); |
770 | 776 | |
771 | | int32 bitsBytesPerPixel = 0; |
| 777 | volatile int32 bitsBytesPerPixel = 0; |
772 | 778 | switch (bitsHeader.colors) { |
773 | 779 | case B_RGBA32: |
774 | 780 | case B_RGBA32_BIG: |
… |
… |
PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
804 | 810 | return B_NO_TRANSLATOR; |
805 | 811 | }; |
806 | 812 | |
807 | | uint8 *pbitsrow = NULL, *prow = NULL; |
| 813 | uint8 * volatile pbitsrow = NULL, * volatile prow = NULL; |
808 | 814 | // row buffers |
809 | 815 | // 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; |
812 | 818 | |
813 | 819 | png_structp ppng = NULL; |
814 | 820 | png_infop pinfo = NULL; |
… |
… |
PNGTranslator::translate_from_bits_to_png(BPositionIO *inSource,
|
886 | 892 | for (png_uint_32 i = 0; i < height; i++) { |
887 | 893 | inSource->Read(pbitsrow, bitsHeader.rowBytes); |
888 | 894 | |
| 895 | // We're casting away pmap's virtualness, not its constness |
889 | 896 | pix_bits_to_png(pbitsrow, prow, bitsHeader.colors, width, |
890 | | pmap, bitsBytesPerPixel); |
| 897 | const_cast<color_map*>(pmap), bitsBytesPerPixel); |
891 | 898 | |
892 | 899 | png_write_row(ppng, prow); |
893 | 900 | } |
… |
… |
BView *
|
985 | 992 | PNGTranslator::NewConfigView(TranslatorSettings *settings) |
986 | 993 | { |
987 | 994 | 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, |
989 | 996 | B_WILL_DRAW, settings); |
990 | 997 | } |
991 | 998 | |