Merge branch 'mingw-w64-warn-fixes'
Fix a few (harmless) warnings when building with gcc 8 from MinGW-w64. See https://github.com/wxWidgets/wxWidgets/pull/854
This commit is contained in:
@@ -257,7 +257,7 @@ inline size_t wxStrlcpy(char *dest, const char *src, size_t n)
|
|||||||
{
|
{
|
||||||
if ( n-- > len )
|
if ( n-- > len )
|
||||||
n = len;
|
n = len;
|
||||||
wxCRT_StrncpyA(dest, src, n);
|
wxTmemcpy(dest, src, n);
|
||||||
dest[n] = '\0';
|
dest[n] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +270,7 @@ inline size_t wxStrlcpy(wchar_t *dest, const wchar_t *src, size_t n)
|
|||||||
{
|
{
|
||||||
if ( n-- > len )
|
if ( n-- > len )
|
||||||
n = len;
|
n = len;
|
||||||
wxCRT_StrncpyW(dest, src, n);
|
wxTmemcpy(dest, src, n);
|
||||||
dest[n] = L'\0';
|
dest[n] = L'\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -68,6 +68,8 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxPNGHandler,wxImageHandler);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
// VS: wxPNGInfoStruct declared below is a hack that needs some explanation.
|
// VS: wxPNGInfoStruct declared below is a hack that needs some explanation.
|
||||||
// First, let me describe what's the problem: libpng uses jmp_buf in
|
// First, let me describe what's the problem: libpng uses jmp_buf in
|
||||||
@@ -93,10 +95,72 @@ struct wxPNGInfoStruct
|
|||||||
wxInputStream *in;
|
wxInputStream *in;
|
||||||
wxOutputStream *out;
|
wxOutputStream *out;
|
||||||
} stream;
|
} stream;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define WX_PNG_INFO(png_ptr) ((wxPNGInfoStruct*)png_get_io_ptr(png_ptr))
|
#define WX_PNG_INFO(png_ptr) ((wxPNGInfoStruct*)png_get_io_ptr(png_ptr))
|
||||||
|
|
||||||
|
// This is another helper struct which is used to pass parameters to
|
||||||
|
// DoLoadPNGFile(). It allows us to use the usual RAII for freeing memory,
|
||||||
|
// which wouldn't be possible inside DoLoadPNGFile() because it uses
|
||||||
|
// setjmp/longjmp() functions for error handling, which are incompatible with
|
||||||
|
// C++ destructors.
|
||||||
|
struct wxPNGImageData
|
||||||
|
{
|
||||||
|
wxPNGImageData()
|
||||||
|
{
|
||||||
|
lines = NULL;
|
||||||
|
numLines = 0;
|
||||||
|
info_ptr = (png_infop) NULL;
|
||||||
|
png_ptr = (png_structp) NULL;
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Alloc(png_uint_32 width, png_uint_32 height)
|
||||||
|
{
|
||||||
|
lines = (unsigned char **)malloc(height * sizeof(unsigned char *));
|
||||||
|
if ( !lines )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for ( png_uint_32 n = 0; n < height; n++ )
|
||||||
|
{
|
||||||
|
lines[n] = (unsigned char *)malloc( (size_t)(width * 4));
|
||||||
|
if ( lines[n] )
|
||||||
|
++numLines;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
~wxPNGImageData()
|
||||||
|
{
|
||||||
|
for ( unsigned int n = 0; n < numLines; n++ )
|
||||||
|
free( lines[n] );
|
||||||
|
|
||||||
|
free( lines );
|
||||||
|
|
||||||
|
if ( png_ptr )
|
||||||
|
{
|
||||||
|
if ( info_ptr )
|
||||||
|
png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
|
||||||
|
else
|
||||||
|
png_destroy_read_struct( &png_ptr, (png_infopp) NULL, (png_infopp) NULL );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo);
|
||||||
|
|
||||||
|
unsigned char** lines;
|
||||||
|
png_uint_32 numLines;
|
||||||
|
png_infop info_ptr;
|
||||||
|
png_structp png_ptr;
|
||||||
|
bool ok;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// helper functions
|
// helper functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -247,28 +311,20 @@ void CopyDataFromPNG(wxImage *image,
|
|||||||
#pragma warning(disable:4611)
|
#pragma warning(disable:4611)
|
||||||
#endif /* VC++ */
|
#endif /* VC++ */
|
||||||
|
|
||||||
bool
|
// This function uses wxPNGImageData to store some of its "local" variables in
|
||||||
wxPNGHandler::LoadFile(wxImage *image,
|
// order to avoid clobbering these variables by longjmp(): having them inside
|
||||||
wxInputStream& stream,
|
// the stack frame of the caller prevents this from happening. It also
|
||||||
bool verbose,
|
// "returns" its result via wxPNGImageData: use its "ok" field to check
|
||||||
int WXUNUSED(index))
|
// whether loading succeeded or failed.
|
||||||
|
void
|
||||||
|
wxPNGImageData::DoLoadPNGFile(wxImage* image, wxPNGInfoStruct& wxinfo)
|
||||||
{
|
{
|
||||||
// VZ: as this function uses setjmp() the only fool-proof error handling
|
png_uint_32 width, height = 0;
|
||||||
// method is to use goto (setjmp is not really C++ dtors friendly...)
|
|
||||||
|
|
||||||
unsigned char **lines = NULL;
|
|
||||||
png_infop info_ptr = (png_infop) NULL;
|
|
||||||
wxPNGInfoStruct wxinfo;
|
|
||||||
|
|
||||||
png_uint_32 i, width, height = 0;
|
|
||||||
int bit_depth, color_type, interlace_type;
|
int bit_depth, color_type, interlace_type;
|
||||||
|
|
||||||
wxinfo.verbose = verbose;
|
|
||||||
wxinfo.stream.in = &stream;
|
|
||||||
|
|
||||||
image->Destroy();
|
image->Destroy();
|
||||||
|
|
||||||
png_structp png_ptr = png_create_read_struct
|
png_ptr = png_create_read_struct
|
||||||
(
|
(
|
||||||
PNG_LIBPNG_VER_STRING,
|
PNG_LIBPNG_VER_STRING,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -276,7 +332,7 @@ wxPNGHandler::LoadFile(wxImage *image,
|
|||||||
wx_PNG_warning
|
wx_PNG_warning
|
||||||
);
|
);
|
||||||
if (!png_ptr)
|
if (!png_ptr)
|
||||||
goto error;
|
return;
|
||||||
|
|
||||||
// NB: please see the comment near wxPNGInfoStruct declaration for
|
// NB: please see the comment near wxPNGInfoStruct declaration for
|
||||||
// explanation why this line is mandatory
|
// explanation why this line is mandatory
|
||||||
@@ -284,10 +340,10 @@ wxPNGHandler::LoadFile(wxImage *image,
|
|||||||
|
|
||||||
info_ptr = png_create_info_struct( png_ptr );
|
info_ptr = png_create_info_struct( png_ptr );
|
||||||
if (!info_ptr)
|
if (!info_ptr)
|
||||||
goto error;
|
return;
|
||||||
|
|
||||||
if (setjmp(wxinfo.jmpbuf))
|
if (setjmp(wxinfo.jmpbuf))
|
||||||
goto error;
|
return;
|
||||||
|
|
||||||
png_read_info( png_ptr, info_ptr );
|
png_read_info( png_ptr, info_ptr );
|
||||||
png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL );
|
png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL );
|
||||||
@@ -308,19 +364,10 @@ wxPNGHandler::LoadFile(wxImage *image,
|
|||||||
image->Create((int)width, (int)height, (bool) false /* no need to init pixels */);
|
image->Create((int)width, (int)height, (bool) false /* no need to init pixels */);
|
||||||
|
|
||||||
if (!image->IsOk())
|
if (!image->IsOk())
|
||||||
goto error;
|
return;
|
||||||
|
|
||||||
// initialize all line pointers to NULL to ensure that they can be safely
|
if ( !Alloc(width, height) )
|
||||||
// free()d if an error occurs before all of them could be allocated
|
return;
|
||||||
lines = (unsigned char **)calloc(height, sizeof(unsigned char *));
|
|
||||||
if ( !lines )
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
for (i = 0; i < height; i++)
|
|
||||||
{
|
|
||||||
if ((lines[i] = (unsigned char *)malloc( (size_t)(width * 4))) == NULL)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
png_read_image( png_ptr, lines );
|
png_read_image( png_ptr, lines );
|
||||||
png_read_end( png_ptr, info_ptr );
|
png_read_end( png_ptr, info_ptr );
|
||||||
@@ -392,47 +439,42 @@ wxPNGHandler::LoadFile(wxImage *image,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
|
|
||||||
|
|
||||||
// loaded successfully, now init wxImage with this data
|
// loaded successfully, now init wxImage with this data
|
||||||
CopyDataFromPNG(image, lines, width, height, color_type);
|
CopyDataFromPNG(image, lines, width, height, color_type);
|
||||||
|
|
||||||
for ( i = 0; i < height; i++ )
|
// This will indicate to the caller that loading succeeded.
|
||||||
free( lines[i] );
|
ok = true;
|
||||||
free( lines );
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
wxPNGHandler::LoadFile(wxImage *image,
|
||||||
|
wxInputStream& stream,
|
||||||
|
bool verbose,
|
||||||
|
int WXUNUSED(index))
|
||||||
|
{
|
||||||
|
wxPNGInfoStruct wxinfo;
|
||||||
|
wxinfo.verbose = verbose;
|
||||||
|
wxinfo.stream.in = &stream;
|
||||||
|
|
||||||
|
wxPNGImageData data;
|
||||||
|
data.DoLoadPNGFile(image, wxinfo);
|
||||||
|
|
||||||
|
if ( !data.ok )
|
||||||
|
{
|
||||||
|
if (verbose)
|
||||||
|
{
|
||||||
|
wxLogError(_("Couldn't load a PNG image - file is corrupted or not enough memory."));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( image->IsOk() )
|
||||||
|
{
|
||||||
|
image->Destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
error:
|
|
||||||
if (verbose)
|
|
||||||
{
|
|
||||||
wxLogError(_("Couldn't load a PNG image - file is corrupted or not enough memory."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( image->IsOk() )
|
|
||||||
{
|
|
||||||
image->Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( lines )
|
|
||||||
{
|
|
||||||
for ( unsigned int n = 0; n < height; n++ )
|
|
||||||
free( lines[n] );
|
|
||||||
|
|
||||||
free( lines );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( png_ptr )
|
|
||||||
{
|
|
||||||
if ( info_ptr )
|
|
||||||
{
|
|
||||||
png_destroy_read_struct( &png_ptr, &info_ptr, (png_infopp) NULL );
|
|
||||||
free(info_ptr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
png_destroy_read_struct( &png_ptr, (png_infopp) NULL, (png_infopp) NULL );
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -231,12 +231,12 @@ void wxStatusBarGeneric::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int
|
|||||||
|
|
||||||
// eventually ellipsize the text so that it fits the field width
|
// eventually ellipsize the text so that it fits the field width
|
||||||
|
|
||||||
wxEllipsizeMode ellmode = (wxEllipsizeMode)-1;
|
wxEllipsizeMode ellmode = wxELLIPSIZE_NONE;
|
||||||
if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START;
|
if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START;
|
||||||
else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE;
|
else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE;
|
||||||
else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END;
|
else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END;
|
||||||
|
|
||||||
if (ellmode == (wxEllipsizeMode)-1)
|
if (ellmode == wxELLIPSIZE_NONE)
|
||||||
{
|
{
|
||||||
// if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if
|
// if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if
|
||||||
// we don't ellipsize the text but just truncate it
|
// we don't ellipsize the text but just truncate it
|
||||||
@@ -267,7 +267,7 @@ void wxStatusBarGeneric::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int
|
|||||||
// draw the text
|
// draw the text
|
||||||
dc.DrawText(text, xpos, ypos);
|
dc.DrawText(text, xpos, ypos);
|
||||||
|
|
||||||
if (ellmode == (wxEllipsizeMode)-1)
|
if (ellmode == wxELLIPSIZE_NONE)
|
||||||
dc.DestroyClippingRegion();
|
dc.DestroyClippingRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -287,12 +287,12 @@ void wxStatusBar::DoUpdateStatusText(int nField)
|
|||||||
wxString text = GetStatusText(nField);
|
wxString text = GetStatusText(nField);
|
||||||
|
|
||||||
// do we need to ellipsize this string?
|
// do we need to ellipsize this string?
|
||||||
wxEllipsizeMode ellmode = (wxEllipsizeMode)-1;
|
wxEllipsizeMode ellmode = wxELLIPSIZE_NONE;
|
||||||
if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START;
|
if (HasFlag(wxSTB_ELLIPSIZE_START)) ellmode = wxELLIPSIZE_START;
|
||||||
else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE;
|
else if (HasFlag(wxSTB_ELLIPSIZE_MIDDLE)) ellmode = wxELLIPSIZE_MIDDLE;
|
||||||
else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END;
|
else if (HasFlag(wxSTB_ELLIPSIZE_END)) ellmode = wxELLIPSIZE_END;
|
||||||
|
|
||||||
if (ellmode == (wxEllipsizeMode)-1)
|
if (ellmode == wxELLIPSIZE_NONE)
|
||||||
{
|
{
|
||||||
// if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if
|
// if we have the wxSTB_SHOW_TIPS we must set the ellipsized flag even if
|
||||||
// we don't ellipsize the text but just truncate it
|
// we don't ellipsize the text but just truncate it
|
||||||
|
@@ -1371,8 +1371,7 @@ void wxPropertyGridPageState::DoRemoveFromSelection( wxPGProperty* prop )
|
|||||||
{
|
{
|
||||||
// If first item (i.e. one with the active editor) was
|
// If first item (i.e. one with the active editor) was
|
||||||
// deselected, then we need to take some extra measures.
|
// deselected, then we need to take some extra measures.
|
||||||
wxArrayPGProperty sel = m_selection;
|
wxArrayPGProperty sel(m_selection.begin() + 1, m_selection.end());
|
||||||
sel.erase( sel.begin() + i );
|
|
||||||
|
|
||||||
wxPGProperty* newFirst = sel.empty()? NULL: sel[0];
|
wxPGProperty* newFirst = sel.empty()? NULL: sel[0];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user