From 1705656eac83cd8b65c2ee895888cd529c62c04c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 24 May 2019 14:21:37 -0400 Subject: [PATCH] Add (void*) casts to memcpy/memset invocations to appease GCC 8. A lot of these classes are not *technically* "trivially copyable" for one reason or another, but in all of these cases it seems OK to me to use memcpy/memset on them. Adding a cast to void* tells GCC that "I know what I'm doing here" and shuts up the warning. --- headers/libs/agg/agg_renderer_scanline.h | 180 +++++++++--------- .../private/debugger/types/ValueLocation.h | 2 +- .../private/interface/TextViewSupportBuffer.h | 27 +-- src/add-ons/translators/gif/SavePalette.cpp | 6 +- .../transformable/TransformPointsBox.cpp | 2 +- src/kits/shared/Variant.cpp | 2 +- src/kits/tracker/OpenHashTable.h | 2 +- src/kits/tracker/PoseView.cpp | 2 +- src/libs/icon/shape/VectorPath.cpp | 6 +- src/preferences/keymap/KeyboardLayout.cpp | 2 +- 10 files changed, 116 insertions(+), 115 deletions(-) diff --git a/headers/libs/agg/agg_renderer_scanline.h b/headers/libs/agg/agg_renderer_scanline.h index 615fffb42b..efa713b20c 100644 --- a/headers/libs/agg/agg_renderer_scanline.h +++ b/headers/libs/agg/agg_renderer_scanline.h @@ -2,8 +2,8 @@ // Anti-Grain Geometry - Version 2.4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // @@ -23,9 +23,9 @@ namespace agg { //================================================render_scanline_aa_solid - template - void render_scanline_aa_solid(const Scanline& sl, - BaseRenderer& ren, + template + void render_scanline_aa_solid(const Scanline& sl, + BaseRenderer& ren, const ColorT& color) { int y = sl.y(); @@ -37,14 +37,14 @@ namespace agg int x = span->x; if(span->len > 0) { - ren.blend_solid_hspan(x, y, (unsigned)span->len, - color, + ren.blend_solid_hspan(x, y, (unsigned)span->len, + color, span->covers); } else { - ren.blend_hline(x, y, (unsigned)(x - span->len - 1), - color, + ren.blend_hline(x, y, (unsigned)(x - span->len - 1), + color, *(span->covers)); } if(--num_spans == 0) break; @@ -53,16 +53,16 @@ namespace agg } //===============================================render_scanlines_aa_solid - template - void render_scanlines_aa_solid(Rasterizer& ras, Scanline& sl, + void render_scanlines_aa_solid(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, const ColorT& color) { if(ras.rewind_scanlines()) { // Explicitly convert "color" to the BaseRenderer color type. // For example, it can be called with color type "rgba", while - // "rgba8" is needed. Otherwise it will be implicitly + // "rgba8" is needed. Otherwise it will be implicitly // converted in the loop many times. //---------------------- typename BaseRenderer::color_type ren_color(color); @@ -72,7 +72,7 @@ namespace agg { //render_scanline_aa_solid(sl, ren, ren_color); - // This code is equivalent to the above call (copy/paste). + // This code is equivalent to the above call (copy/paste). // It's just a "manual" optimization for old compilers, // like Microsoft Visual C++ v6.0 //------------------------------- @@ -85,14 +85,14 @@ namespace agg int x = span->x; if(span->len > 0) { - ren.blend_solid_hspan(x, y, (unsigned)span->len, - ren_color, + ren.blend_solid_hspan(x, y, (unsigned)span->len, + ren_color, span->covers); } else { - ren.blend_hline(x, y, (unsigned)(x - span->len - 1), - ren_color, + ren.blend_hline(x, y, (unsigned)(x - span->len - 1), + ren_color, *(span->covers)); } if(--num_spans == 0) break; @@ -116,7 +116,7 @@ namespace agg { m_ren = &ren; } - + //-------------------------------------------------------------------- void color(const color_type& c) { m_color = c; } const color_type& color() const { return m_color; } @@ -129,7 +129,7 @@ namespace agg { render_scanline_aa_solid(sl, *m_ren, m_color); } - + private: base_ren_type* m_ren; color_type m_color; @@ -148,9 +148,9 @@ namespace agg //======================================================render_scanline_aa - template - void render_scanline_aa(const Scanline& sl, BaseRenderer& ren, + template + void render_scanline_aa(const Scanline& sl, BaseRenderer& ren, SpanAllocator& alloc, SpanGenerator& span_gen) { int y = sl.y(); @@ -166,7 +166,7 @@ namespace agg if(len < 0) len = -len; typename BaseRenderer::color_type* colors = alloc.allocate(len); span_gen.generate(colors, x, y, len); - ren.blend_color_hspan(x, y, len, colors, + ren.blend_color_hspan(x, y, len, colors, (span->len < 0) ? 0 : covers, *covers); if(--num_spans == 0) break; @@ -175,9 +175,9 @@ namespace agg } //=====================================================render_scanlines_aa - template - void render_scanlines_aa(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, + void render_scanlines_aa(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, SpanAllocator& alloc, SpanGenerator& span_gen) { if(ras.rewind_scanlines()) @@ -192,7 +192,7 @@ namespace agg } //====================================================renderer_scanline_aa - template + template class renderer_scanline_aa { public: @@ -202,22 +202,22 @@ namespace agg //-------------------------------------------------------------------- renderer_scanline_aa() : m_ren(0), m_alloc(0), m_span_gen(0) {} - renderer_scanline_aa(base_ren_type& ren, - alloc_type& alloc, + renderer_scanline_aa(base_ren_type& ren, + alloc_type& alloc, span_gen_type& span_gen) : m_ren(&ren), m_alloc(&alloc), m_span_gen(&span_gen) {} - void attach(base_ren_type& ren, - alloc_type& alloc, + void attach(base_ren_type& ren, + alloc_type& alloc, span_gen_type& span_gen) { m_ren = &ren; m_alloc = &alloc; m_span_gen = &span_gen; } - + //-------------------------------------------------------------------- void prepare() { m_span_gen->prepare(); } @@ -239,21 +239,21 @@ namespace agg //===============================================render_scanline_bin_solid - template - void render_scanline_bin_solid(const Scanline& sl, - BaseRenderer& ren, + template + void render_scanline_bin_solid(const Scanline& sl, + BaseRenderer& ren, const ColorT& color) { unsigned num_spans = sl.num_spans(); typename Scanline::const_iterator span = sl.begin(); for(;;) { - ren.blend_hline(span->x, - sl.y(), - span->x - 1 + ((span->len < 0) ? - -span->len : - span->len), - color, + ren.blend_hline(span->x, + sl.y(), + span->x - 1 + ((span->len < 0) ? + -span->len : + span->len), + color, cover_full); if(--num_spans == 0) break; ++span; @@ -261,16 +261,16 @@ namespace agg } //==============================================render_scanlines_bin_solid - template - void render_scanlines_bin_solid(Rasterizer& ras, Scanline& sl, + void render_scanlines_bin_solid(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, const ColorT& color) { if(ras.rewind_scanlines()) { // Explicitly convert "color" to the BaseRenderer color type. // For example, it can be called with color type "rgba", while - // "rgba8" is needed. Otherwise it will be implicitly + // "rgba8" is needed. Otherwise it will be implicitly // converted in the loop many times. //---------------------- typename BaseRenderer::color_type ren_color(color); @@ -280,7 +280,7 @@ namespace agg { //render_scanline_bin_solid(sl, ren, ren_color); - // This code is equivalent to the above call (copy/paste). + // This code is equivalent to the above call (copy/paste). // It's just a "manual" optimization for old compilers, // like Microsoft Visual C++ v6.0 //------------------------------- @@ -288,12 +288,12 @@ namespace agg typename Scanline::const_iterator span = sl.begin(); for(;;) { - ren.blend_hline(span->x, - sl.y(), - span->x - 1 + ((span->len < 0) ? - -span->len : - span->len), - ren_color, + ren.blend_hline(span->x, + sl.y(), + span->x - 1 + ((span->len < 0) ? + -span->len : + span->len), + ren_color, cover_full); if(--num_spans == 0) break; ++span; @@ -316,7 +316,7 @@ namespace agg { m_ren = &ren; } - + //-------------------------------------------------------------------- void color(const color_type& c) { m_color = c; } const color_type& color() const { return m_color; } @@ -329,7 +329,7 @@ namespace agg { render_scanline_bin_solid(sl, *m_ren, m_color); } - + private: base_ren_type* m_ren; color_type m_color; @@ -343,9 +343,9 @@ namespace agg //======================================================render_scanline_bin - template - void render_scanline_bin(const Scanline& sl, BaseRenderer& ren, + template + void render_scanline_bin(const Scanline& sl, BaseRenderer& ren, SpanAllocator& alloc, SpanGenerator& span_gen) { int y = sl.y(); @@ -359,16 +359,16 @@ namespace agg if(len < 0) len = -len; typename BaseRenderer::color_type* colors = alloc.allocate(len); span_gen.generate(colors, x, y, len); - ren.blend_color_hspan(x, y, len, colors, 0, cover_full); + ren.blend_color_hspan(x, y, len, colors, 0, cover_full); if(--num_spans == 0) break; ++span; } } //=====================================================render_scanlines_bin - template - void render_scanlines_bin(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, + void render_scanlines_bin(Rasterizer& ras, Scanline& sl, BaseRenderer& ren, SpanAllocator& alloc, SpanGenerator& span_gen) { if(ras.rewind_scanlines()) @@ -383,7 +383,7 @@ namespace agg } //====================================================renderer_scanline_bin - template + template class renderer_scanline_bin { public: @@ -393,22 +393,22 @@ namespace agg //-------------------------------------------------------------------- renderer_scanline_bin() : m_ren(0), m_alloc(0), m_span_gen(0) {} - renderer_scanline_bin(base_ren_type& ren, - alloc_type& alloc, + renderer_scanline_bin(base_ren_type& ren, + alloc_type& alloc, span_gen_type& span_gen) : m_ren(&ren), m_alloc(&alloc), m_span_gen(&span_gen) {} - void attach(base_ren_type& ren, - alloc_type& alloc, + void attach(base_ren_type& ren, + alloc_type& alloc, span_gen_type& span_gen) { m_ren = &ren; m_alloc = &alloc; m_span_gen = &span_gen; } - + //-------------------------------------------------------------------- void prepare() { m_span_gen->prepare(); } @@ -449,13 +449,13 @@ namespace agg } //========================================================render_all_paths - template - void render_all_paths(Rasterizer& ras, + void render_all_paths(Rasterizer& ras, Scanline& sl, - Renderer& r, - VertexSource& vs, - const ColorStorage& as, + Renderer& r, + VertexSource& vs, + const ColorStorage& as, const PathId& path_id, unsigned num_paths) { @@ -477,13 +477,13 @@ namespace agg //=============================================render_scanlines_compound - template - void render_scanlines_compound(Rasterizer& ras, + void render_scanlines_compound(Rasterizer& ras, ScanlineAA& sl_aa, ScanlineBin& sl_bin, BaseRenderer& ren, @@ -530,14 +530,14 @@ namespace agg for(;;) { len = span_aa->len; - sh.generate_span(color_span, - span_aa->x, - sl_aa.y(), - len, + sh.generate_span(color_span, + span_aa->x, + sl_aa.y(), + len, style); - ren.blend_color_hspan(span_aa->x, - sl_aa.y(), + ren.blend_color_hspan(span_aa->x, + sl_aa.y(), span_aa->len, color_span, span_aa->covers); @@ -554,12 +554,12 @@ namespace agg if(sl_len) { - memset(mix_buffer + sl_start - min_x, - 0, + memset((void*)(mix_buffer + sl_start - min_x), + 0, sl_len * sizeof(color_type)); - memset(cover_buffer + sl_start - min_x, - 0, + memset(cover_buffer + sl_start - min_x, + 0, sl_len * sizeof(cover_type)); int sl_y = 0x7FFFFFFF; @@ -620,10 +620,10 @@ namespace agg len = span_aa->len; colors = mix_buffer + span_aa->x - min_x; cspan = color_span; - sh.generate_span(cspan, - span_aa->x, - sl_aa.y(), - len, + sh.generate_span(cspan, + span_aa->x, + sl_aa.y(), + len, style); src_covers = span_aa->covers; dst_covers = cover_buffer + span_aa->x - min_x; @@ -651,8 +651,8 @@ namespace agg } } } - ren.blend_color_hspan(sl_start, - sl_y, + ren.blend_color_hspan(sl_start, + sl_y, sl_len, mix_buffer + sl_start - min_x, 0, diff --git a/headers/private/debugger/types/ValueLocation.h b/headers/private/debugger/types/ValueLocation.h index 045e7db91e..5ea82eb10f 100644 --- a/headers/private/debugger/types/ValueLocation.h +++ b/headers/private/debugger/types/ValueLocation.h @@ -72,7 +72,7 @@ struct ValuePieceLocation { bool Copy(const ValuePieceLocation& other) { - memcpy(this, &other, sizeof(ValuePieceLocation)); + memcpy((void*)this, (void*)&other, sizeof(ValuePieceLocation)); if (type == VALUE_PIECE_LOCATION_IMPLICIT) { void* tempValue = malloc(size); if (tempValue == NULL) { diff --git a/headers/private/interface/TextViewSupportBuffer.h b/headers/private/interface/TextViewSupportBuffer.h index 52cf15b291..7d5b670a1c 100644 --- a/headers/private/interface/TextViewSupportBuffer.h +++ b/headers/private/interface/TextViewSupportBuffer.h @@ -27,8 +27,8 @@ virtual ~_BTextViewSupportBuffer_(); int32 ItemCount() const; protected: - int32 fExtraCount; - int32 fItemCount; + int32 fExtraCount; + int32 fItemCount; int32 fBufferCount; T* fBuffer; }; @@ -61,7 +61,7 @@ _BTextViewSupportBuffer_::InsertItemsAt(int32 inNumItems, { if (inNumItems < 1) return; - + inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex; inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex; @@ -69,15 +69,16 @@ _BTextViewSupportBuffer_::InsertItemsAt(int32 inNumItems, int32 logSize = fItemCount * sizeof(T); if ((logSize + delta) >= fBufferCount) { fBufferCount = logSize + delta + (fExtraCount * sizeof(T)); - fBuffer = (T*)realloc(fBuffer, fBufferCount); + fBuffer = (T*)realloc((void*)fBuffer, fBufferCount); if (fBuffer == NULL) debugger("InsertItemsAt(): reallocation failed"); } - + T* loc = fBuffer + inAtIndex; - memmove(loc + inNumItems, loc, (fItemCount - inAtIndex) * sizeof(T)); - memcpy(loc, inItem, delta); - + memmove((void*)(loc + inNumItems), (void*)loc, + (fItemCount - inAtIndex) * sizeof(T)); + memcpy((void*)loc, (void*)inItem, delta); + fItemCount += inNumItems; } @@ -89,14 +90,14 @@ _BTextViewSupportBuffer_::RemoveItemsAt(int32 inNumItems, { if (inNumItems < 1) return; - + inAtIndex = (inAtIndex > fItemCount - 1) ? (fItemCount - 1) : inAtIndex; inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex; - + T* loc = fBuffer + inAtIndex; - memmove(loc, loc + inNumItems, + memmove(loc, loc + inNumItems, (fItemCount - (inNumItems + inAtIndex)) * sizeof(T)); - + int32 delta = inNumItems * sizeof(T); int32 logSize = fItemCount * sizeof(T); uint32 extraSize = fBufferCount - (logSize - delta); @@ -106,7 +107,7 @@ _BTextViewSupportBuffer_::RemoveItemsAt(int32 inNumItems, if (fBuffer == NULL) debugger("RemoveItemsAt(): reallocation failed"); } - + fItemCount -= inNumItems; } diff --git a/src/add-ons/translators/gif/SavePalette.cpp b/src/add-ons/translators/gif/SavePalette.cpp index 329d02cb6f..39b2647ed2 100644 --- a/src/add-ons/translators/gif/SavePalette.cpp +++ b/src/add-ons/translators/gif/SavePalette.cpp @@ -198,11 +198,11 @@ SavePalette::SavePalette(int mode) { if (IsValid()) { if (fMode == WEB_SAFE_PALETTE) { - memcpy(pal, wsp, sizeof(rgb_color) * 256); + memcpy((void*)pal, wsp, sizeof(rgb_color) * 256); fSize = 216; } else if (fMode == BEOS_SYSTEM_PALETTE) { color_map* map = (color_map*)system_colors(); - memcpy(pal, map->color_list, sizeof(rgb_color) * 256); + memcpy((void*)pal, map->color_list, sizeof(rgb_color) * 256); fSize = 256; } else if (fMode == GREYSCALE_PALETTE) { for (int i = 0; i < 256; i++) { @@ -405,7 +405,7 @@ SavePalette::IndexForColor(uint8 red, uint8 green, uint8 blue, uint8 alpha) } } else { int closestDistance = 255 * 255 * 3; - + if (fTransparentMode == AUTO_TRANSPARENCY) { for (int i = 0; i < fTransparentIndex && closestDistance != 0; i++) { diff --git a/src/apps/icon-o-matic/transformable/TransformPointsBox.cpp b/src/apps/icon-o-matic/transformable/TransformPointsBox.cpp index c3f2c665c8..bb262dc1df 100644 --- a/src/apps/icon-o-matic/transformable/TransformPointsBox.cpp +++ b/src/apps/icon-o-matic/transformable/TransformPointsBox.cpp @@ -57,7 +57,7 @@ TransformPointsBox::TransformPointsBox(CanvasView* view, fPoints[i].point_out.x, fPoints[i].point_out.y); bounds = bounds | dummy; } else { - memset(&fPoints[i], 0, sizeof(control_point)); + memset((void*)&fPoints[i], 0, sizeof(control_point)); } } } diff --git a/src/kits/shared/Variant.cpp b/src/kits/shared/Variant.cpp index 7d32e42c1d..c10ba8db4b 100644 --- a/src/kits/shared/Variant.cpp +++ b/src/kits/shared/Variant.cpp @@ -353,7 +353,7 @@ BVariant::_SetTo(const BVariant& other) other.fReferenceable->AcquireReference(); } - memcpy(this, &other, sizeof(BVariant)); + memcpy((void*)this, (void*)&other, sizeof(BVariant)); } diff --git a/src/kits/tracker/OpenHashTable.h b/src/kits/tracker/OpenHashTable.h index eb000595c6..d7cfb3f467 100644 --- a/src/kits/tracker/OpenHashTable.h +++ b/src/kits/tracker/OpenHashTable.h @@ -474,7 +474,7 @@ OpenHashElementArray::Add() memcpy(newData, fData, fSize * sizeof(Element)); free(fData); */ - Element *newData = (Element*)realloc(fData, + Element *newData = (Element*)realloc((void*)fData, (size_t)newSize * sizeof(Element)); if (!newData) return NULL; diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 7aa0f65e11..8dcf25f507 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -788,7 +788,7 @@ BPoseView::SavePoseLocations(BRect* frameIfDesktop) extendedPoseInfo = (ExtendedPoseInfo*) new char [size]; - memset(extendedPoseInfo, 0, size); + memset((void*)extendedPoseInfo, 0, size); extendedPoseInfo->fWorkspaces = 0xffffffff; extendedPoseInfo->fInvisible = false; extendedPoseInfo->fShowFromBootOnly = false; diff --git a/src/libs/icon/shape/VectorPath.cpp b/src/libs/icon/shape/VectorPath.cpp index 4e4f7ba560..db7d345d2a 100644 --- a/src/libs/icon/shape/VectorPath.cpp +++ b/src/libs/icon/shape/VectorPath.cpp @@ -145,7 +145,7 @@ VectorPath::VectorPath(BMessage* archive) if (archive->GetInfo("point", &typeFound, &countFound) >= B_OK && typeFound == B_POINT_TYPE && _SetPointCount(countFound)) { - memset(fPath, 0, fAllocCount * sizeof(control_point)); + memset((void*)fPath, 0, fAllocCount * sizeof(control_point)); BPoint point; BPoint pointIn; @@ -322,7 +322,7 @@ VectorPath::operator==(const VectorPath& other) const { if (fClosed != other.fClosed) return false; - + if (fPointCount != other.fPointCount) return false; @@ -1073,7 +1073,7 @@ VectorPath::_SetPointCount(int32 count) fPath = obj_new(control_point, fAllocCount); if (fPath != NULL) { - memset(fPath + fPointCount, 0, + memset((void*)(fPath + fPointCount), 0, (fAllocCount - fPointCount) * sizeof(control_point)); } } diff --git a/src/preferences/keymap/KeyboardLayout.cpp b/src/preferences/keymap/KeyboardLayout.cpp index 01ad5cf720..1b50ec0b25 100644 --- a/src/preferences/keymap/KeyboardLayout.cpp +++ b/src/preferences/keymap/KeyboardLayout.cpp @@ -842,7 +842,7 @@ KeyboardLayout::_InitFrom(const char* data) state.mode = kKeyShape; break; case kKeyShape: - memset(&key, 0, sizeof(Key)); + memset((void*)&key, 0, sizeof(Key)); if (!_GetShape(state, term.String(), key)) return B_BAD_VALUE;