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.
This commit is contained in:
Augustin Cavalier
2019-05-24 16:10:13 -04:00
parent 057b69a774
commit 3ca2e85bfd
9 changed files with 18 additions and 17 deletions
+2 -2
View File
@@ -61,8 +61,8 @@ public:
opSize = other.opSize; opSize = other.opSize;
ptCount = other.ptCount; ptCount = other.ptCount;
ptSize = other.ptSize; ptSize = other.ptSize;
memcpy(opList, other.opList, opSize); memcpy((void*)opList, other.opList, opSize);
memcpy(ptList, other.ptList, ptSize); memcpy((void*)ptList, other.ptList, ptSize);
} }
BRect DetermineBoundingBox() const BRect DetermineBoundingBox() const
@@ -33,7 +33,7 @@ NudgePointsCommand::NudgePointsCommand(VectorPath* path,
0.0, 0.0,
1.0, 1.0,
1.0, 1.0,
count > 1 ? B_TRANSLATE("Nudge Control Points") : count > 1 ? B_TRANSLATE("Nudge Control Points") :
B_TRANSLATE("Nudge Control Point"), B_TRANSLATE("Nudge Control Point"),
// count > 1 ? NUDGE_CONTROL_POINTS : NUDGE_CONTROL_POINT), // count > 1 ? NUDGE_CONTROL_POINTS : NUDGE_CONTROL_POINT),
-1), -1),
@@ -48,7 +48,7 @@ NudgePointsCommand::NudgePointsCommand(VectorPath* path,
} }
if (fCount > 0 && points) { if (fCount > 0 && points) {
fPoints = new (nothrow) control_point[fCount]; fPoints = new (nothrow) control_point[fCount];
memcpy(fPoints, points, fCount * sizeof(control_point)); memcpy((void*)fPoints, points, fCount * sizeof(control_point));
} }
} }
@@ -52,7 +52,7 @@ TransformPointsCommand::TransformPointsCommand(
return; return;
memcpy(fIndices, indices, fCount * sizeof(int32)); memcpy(fIndices, indices, fCount * sizeof(int32));
memcpy(fPoints, points, fCount * sizeof(control_point)); memcpy((void*)fPoints, points, fCount * sizeof(control_point));
if (fTransformBox) if (fTransformBox)
fTransformBox->AddListener(this); fTransformBox->AddListener(this);
+2 -2
View File
@@ -126,7 +126,7 @@ draw_polygon(void* _context, size_t numPoints, const BPoint _points[],
return; return;
} }
memcpy(points, _points, numPoints * sizeof(BPoint)); memcpy((void*)points, _points, numPoints * sizeof(BPoint));
((void (*)(void*, int32, BPoint*, bool)) ((void (*)(void*, int32, BPoint*, bool))
context->function_table[fill ? 14 : 13])(context->user_data, numPoints, 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; return;
} }
memcpy(rects, _rects, numRects * sizeof(BRect)); memcpy((void*)rects, _rects, numRects * sizeof(BRect));
((void (*)(void*, BRect*, uint32))context->function_table[20])( ((void (*)(void*, BRect*, uint32))context->function_table[20])(
context->user_data, rects, numRects); context->user_data, rects, numRects);
+2 -2
View File
@@ -164,7 +164,7 @@ BPolygon::_AddPoints(const BPoint* points, int32 count, bool computeBounds)
return false; return false;
} }
BPoint* newPoints = (BPoint*)realloc(fPoints, (fCount + count) BPoint* newPoints = (BPoint*)realloc((void*)fPoints, (fCount + count)
* sizeof(BPoint)); * sizeof(BPoint));
if (newPoints == NULL) { if (newPoints == NULL) {
fprintf(stderr, "BPolygon::_AddPoints(%" B_PRId32 ") out of memory\n", 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; fPoints = newPoints;
memcpy(fPoints + fCount, points, count * sizeof(BPoint)); memcpy((void*)(fPoints + fCount), points, count * sizeof(BPoint));
fCount += count; fCount += count;
if (computeBounds) if (computeBounds)
+4 -3
View File
@@ -336,7 +336,7 @@ BShape::AddShape(const BShape* otherShape)
otherData->opCount * sizeof(uint32)); otherData->opCount * sizeof(uint32));
data->opCount += otherData->opCount; data->opCount += otherData->opCount;
memcpy(data->ptList + data->ptCount, otherData->ptList, memcpy((void*)(data->ptList + data->ptCount), otherData->ptList,
otherData->ptCount * sizeof(BPoint)); otherData->ptCount * sizeof(BPoint));
data->ptCount += otherData->ptCount; data->ptCount += otherData->ptCount;
@@ -568,7 +568,7 @@ BShape::SetData(int32 opCount, int32 ptCount, const uint32* opList,
fBuildingOp = data->opList[data->opCount - 1]; fBuildingOp = data->opList[data->opCount - 1];
if (ptCount > 0) { if (ptCount > 0) {
memcpy(data->ptList, ptList, ptCount * sizeof(BPoint)); memcpy((void*)data->ptList, ptList, ptCount * sizeof(BPoint));
data->ptCount = ptCount; data->ptCount = ptCount;
} }
} }
@@ -620,7 +620,8 @@ BShape::AllocatePts(int32 count)
if (data->ptSize >= newSize) if (data->ptSize >= newSize)
return true; return true;
BPoint* resizedArray = (BPoint*)realloc(data->ptList, newSize * sizeof(BPoint)); BPoint* resizedArray = (BPoint*)realloc((void*)data->ptList,
newSize * sizeof(BPoint));
if (resizedArray) { if (resizedArray) {
data->ptList = resizedArray; data->ptList = resizedArray;
data->ptSize = newSize; data->ptSize = newSize;
+2 -2
View File
@@ -40,7 +40,7 @@
#define obj_new(type, n) ((type *)malloc ((n) * sizeof(type))) #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 obj_free free
#define ALLOC_CHUNKS 20 #define ALLOC_CHUNKS 20
@@ -303,7 +303,7 @@ VectorPath::operator=(const VectorPath& from)
_SetPointCount(from.fPointCount); _SetPointCount(from.fPointCount);
fClosed = from.fClosed; fClosed = from.fClosed;
if (fPath) { if (fPath) {
memcpy(fPath, from.fPath, fPointCount * sizeof(control_point)); memcpy((void*)fPath, from.fPath, fPointCount * sizeof(control_point));
fCachedBounds = from.fCachedBounds; fCachedBounds = from.fCachedBounds;
} else { } else {
fprintf(stderr, "VectorPath() -> allocation failed in operator=!\n"); fprintf(stderr, "VectorPath() -> allocation failed in operator=!\n");
+1 -1
View File
@@ -357,7 +357,7 @@ KeyboardLayout::_AddKey(const Key& key)
if (fKeyCount + 1 > fKeyCapacity) { if (fKeyCount + 1 > fKeyCapacity) {
// enlarge array // enlarge array
int32 newCapacity = fKeyCapacity + 32; int32 newCapacity = fKeyCapacity + 32;
Key* newKeys = (Key*)realloc(fKeys, newCapacity * sizeof(Key)); Key* newKeys = (Key*)realloc((void*)fKeys, newCapacity * sizeof(Key));
if (newKeys == NULL) if (newKeys == NULL)
return false; return false;
+2 -2
View File
@@ -498,7 +498,7 @@ clip_to_picture(void* _canvas, int32 pictureToken, const BPoint& where,
ServerPicture* picture = canvas->GetPicture(pictureToken); ServerPicture* picture = canvas->GetPicture(pictureToken);
if (picture == NULL) if (picture == NULL)
return; return;
AlphaMask* mask = new(std::nothrow) PictureAlphaMask(canvas->GetAlphaMask(), AlphaMask* mask = new(std::nothrow) PictureAlphaMask(canvas->GetAlphaMask(),
picture, *canvas->CurrentState(), where, clipToInverse); picture, *canvas->CurrentState(), where, clipToInverse);
canvas->SetAlphaMask(mask); canvas->SetAlphaMask(mask);
canvas->CurrentState()->GetAlphaMask()->SetCanvasGeometry(BPoint(0, 0), 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)); shapeData.opList = (uint32*)malloc(opCount * sizeof(uint32));
memcpy(shapeData.opList, opList, opCount * sizeof(uint32)); memcpy(shapeData.opList, opList, opCount * sizeof(uint32));
shapeData.ptList = (BPoint*)malloc(ptCount * sizeof(BPoint)); 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.opCount = opCount;
shapeData.opSize = opCount * sizeof(uint32); shapeData.opSize = opCount * sizeof(uint32);