From 3ca2e85bfdeee3bcfd3194c208a42e961eea1c96 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 24 May 2019 16:10:13 -0400 Subject: [PATCH] Interface: Add casts to memcpy/memset invocations on BPoint & BRect. Their copy constructors are exactly what GCC would generate, but we can't remove them because doing so would make them trivially copyable, and so they would be passed in registers on x86_64, an ABI breakage. So instead we have to add explicit casts to void* here. --- headers/private/interface/ShapePrivate.h | 4 ++-- .../icon-o-matic/shape/commands/NudgePointsCommand.cpp | 4 ++-- .../icon-o-matic/shape/commands/TransformPointsCommand.cpp | 2 +- src/kits/interface/PicturePlayer.cpp | 4 ++-- src/kits/interface/Polygon.cpp | 4 ++-- src/kits/interface/Shape.cpp | 7 ++++--- src/libs/icon/shape/VectorPath.cpp | 4 ++-- src/preferences/keymap/KeyboardLayout.cpp | 2 +- src/servers/app/ServerPicture.cpp | 4 ++-- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/headers/private/interface/ShapePrivate.h b/headers/private/interface/ShapePrivate.h index e4c2832cfe..204081550b 100644 --- a/headers/private/interface/ShapePrivate.h +++ b/headers/private/interface/ShapePrivate.h @@ -61,8 +61,8 @@ public: opSize = other.opSize; ptCount = other.ptCount; ptSize = other.ptSize; - memcpy(opList, other.opList, opSize); - memcpy(ptList, other.ptList, ptSize); + memcpy((void*)opList, other.opList, opSize); + memcpy((void*)ptList, other.ptList, ptSize); } BRect DetermineBoundingBox() const diff --git a/src/apps/icon-o-matic/shape/commands/NudgePointsCommand.cpp b/src/apps/icon-o-matic/shape/commands/NudgePointsCommand.cpp index d395d41d48..5115cc13db 100644 --- a/src/apps/icon-o-matic/shape/commands/NudgePointsCommand.cpp +++ b/src/apps/icon-o-matic/shape/commands/NudgePointsCommand.cpp @@ -33,7 +33,7 @@ NudgePointsCommand::NudgePointsCommand(VectorPath* path, 0.0, 1.0, 1.0, - count > 1 ? B_TRANSLATE("Nudge Control Points") : + count > 1 ? B_TRANSLATE("Nudge Control Points") : B_TRANSLATE("Nudge Control Point"), // count > 1 ? NUDGE_CONTROL_POINTS : NUDGE_CONTROL_POINT), -1), @@ -48,7 +48,7 @@ NudgePointsCommand::NudgePointsCommand(VectorPath* path, } if (fCount > 0 && points) { fPoints = new (nothrow) control_point[fCount]; - memcpy(fPoints, points, fCount * sizeof(control_point)); + memcpy((void*)fPoints, points, fCount * sizeof(control_point)); } } diff --git a/src/apps/icon-o-matic/shape/commands/TransformPointsCommand.cpp b/src/apps/icon-o-matic/shape/commands/TransformPointsCommand.cpp index e40f71e797..db5a9562f2 100644 --- a/src/apps/icon-o-matic/shape/commands/TransformPointsCommand.cpp +++ b/src/apps/icon-o-matic/shape/commands/TransformPointsCommand.cpp @@ -52,7 +52,7 @@ TransformPointsCommand::TransformPointsCommand( return; memcpy(fIndices, indices, fCount * sizeof(int32)); - memcpy(fPoints, points, fCount * sizeof(control_point)); + memcpy((void*)fPoints, points, fCount * sizeof(control_point)); if (fTransformBox) fTransformBox->AddListener(this); diff --git a/src/kits/interface/PicturePlayer.cpp b/src/kits/interface/PicturePlayer.cpp index 2abeba8f28..bf2a2c9788 100644 --- a/src/kits/interface/PicturePlayer.cpp +++ b/src/kits/interface/PicturePlayer.cpp @@ -126,7 +126,7 @@ draw_polygon(void* _context, size_t numPoints, const BPoint _points[], return; } - memcpy(points, _points, numPoints * sizeof(BPoint)); + memcpy((void*)points, _points, numPoints * sizeof(BPoint)); ((void (*)(void*, int32, BPoint*, bool)) context->function_table[fill ? 14 : 13])(context->user_data, numPoints, @@ -205,7 +205,7 @@ set_clipping_rects(void* _context, size_t numRects, const BRect _rects[]) return; } - memcpy(rects, _rects, numRects * sizeof(BRect)); + memcpy((void*)rects, _rects, numRects * sizeof(BRect)); ((void (*)(void*, BRect*, uint32))context->function_table[20])( context->user_data, rects, numRects); diff --git a/src/kits/interface/Polygon.cpp b/src/kits/interface/Polygon.cpp index 0a523160b2..a2a5513f27 100644 --- a/src/kits/interface/Polygon.cpp +++ b/src/kits/interface/Polygon.cpp @@ -164,7 +164,7 @@ BPolygon::_AddPoints(const BPoint* points, int32 count, bool computeBounds) return false; } - BPoint* newPoints = (BPoint*)realloc(fPoints, (fCount + count) + BPoint* newPoints = (BPoint*)realloc((void*)fPoints, (fCount + count) * sizeof(BPoint)); if (newPoints == NULL) { fprintf(stderr, "BPolygon::_AddPoints(%" B_PRId32 ") out of memory\n", @@ -173,7 +173,7 @@ BPolygon::_AddPoints(const BPoint* points, int32 count, bool computeBounds) } fPoints = newPoints; - memcpy(fPoints + fCount, points, count * sizeof(BPoint)); + memcpy((void*)(fPoints + fCount), points, count * sizeof(BPoint)); fCount += count; if (computeBounds) diff --git a/src/kits/interface/Shape.cpp b/src/kits/interface/Shape.cpp index d6e195da78..903715db7b 100644 --- a/src/kits/interface/Shape.cpp +++ b/src/kits/interface/Shape.cpp @@ -336,7 +336,7 @@ BShape::AddShape(const BShape* otherShape) otherData->opCount * sizeof(uint32)); data->opCount += otherData->opCount; - memcpy(data->ptList + data->ptCount, otherData->ptList, + memcpy((void*)(data->ptList + data->ptCount), otherData->ptList, otherData->ptCount * sizeof(BPoint)); data->ptCount += otherData->ptCount; @@ -568,7 +568,7 @@ BShape::SetData(int32 opCount, int32 ptCount, const uint32* opList, fBuildingOp = data->opList[data->opCount - 1]; if (ptCount > 0) { - memcpy(data->ptList, ptList, ptCount * sizeof(BPoint)); + memcpy((void*)data->ptList, ptList, ptCount * sizeof(BPoint)); data->ptCount = ptCount; } } @@ -620,7 +620,8 @@ BShape::AllocatePts(int32 count) if (data->ptSize >= newSize) return true; - BPoint* resizedArray = (BPoint*)realloc(data->ptList, newSize * sizeof(BPoint)); + BPoint* resizedArray = (BPoint*)realloc((void*)data->ptList, + newSize * sizeof(BPoint)); if (resizedArray) { data->ptList = resizedArray; data->ptSize = newSize; diff --git a/src/libs/icon/shape/VectorPath.cpp b/src/libs/icon/shape/VectorPath.cpp index db7d345d2a..c43793dd0f 100644 --- a/src/libs/icon/shape/VectorPath.cpp +++ b/src/libs/icon/shape/VectorPath.cpp @@ -40,7 +40,7 @@ #define obj_new(type, n) ((type *)malloc ((n) * sizeof(type))) -#define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type))) +#define obj_renew(p, type, n) ((type *)realloc ((void *)p, (n) * sizeof(type))) #define obj_free free #define ALLOC_CHUNKS 20 @@ -303,7 +303,7 @@ VectorPath::operator=(const VectorPath& from) _SetPointCount(from.fPointCount); fClosed = from.fClosed; if (fPath) { - memcpy(fPath, from.fPath, fPointCount * sizeof(control_point)); + memcpy((void*)fPath, from.fPath, fPointCount * sizeof(control_point)); fCachedBounds = from.fCachedBounds; } else { fprintf(stderr, "VectorPath() -> allocation failed in operator=!\n"); diff --git a/src/preferences/keymap/KeyboardLayout.cpp b/src/preferences/keymap/KeyboardLayout.cpp index 1b50ec0b25..c8d06a84f5 100644 --- a/src/preferences/keymap/KeyboardLayout.cpp +++ b/src/preferences/keymap/KeyboardLayout.cpp @@ -357,7 +357,7 @@ KeyboardLayout::_AddKey(const Key& key) if (fKeyCount + 1 > fKeyCapacity) { // enlarge array int32 newCapacity = fKeyCapacity + 32; - Key* newKeys = (Key*)realloc(fKeys, newCapacity * sizeof(Key)); + Key* newKeys = (Key*)realloc((void*)fKeys, newCapacity * sizeof(Key)); if (newKeys == NULL) return false; diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 4d99d17a97..3e26ff5f1b 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -498,7 +498,7 @@ clip_to_picture(void* _canvas, int32 pictureToken, const BPoint& where, ServerPicture* picture = canvas->GetPicture(pictureToken); if (picture == NULL) return; - AlphaMask* mask = new(std::nothrow) PictureAlphaMask(canvas->GetAlphaMask(), + AlphaMask* mask = new(std::nothrow) PictureAlphaMask(canvas->GetAlphaMask(), picture, *canvas->CurrentState(), where, clipToInverse); canvas->SetAlphaMask(mask); canvas->CurrentState()->GetAlphaMask()->SetCanvasGeometry(BPoint(0, 0), @@ -836,7 +836,7 @@ clip_to_shape(void* _canvas, int32 opCount, const uint32 opList[], shapeData.opList = (uint32*)malloc(opCount * sizeof(uint32)); memcpy(shapeData.opList, opList, opCount * sizeof(uint32)); shapeData.ptList = (BPoint*)malloc(ptCount * sizeof(BPoint)); - memcpy(shapeData.ptList, ptList, ptCount * sizeof(BPoint)); + memcpy((void*)shapeData.ptList, ptList, ptCount * sizeof(BPoint)); shapeData.opCount = opCount; shapeData.opSize = opCount * sizeof(uint32);