vfs: check userland buffers before reading them.
[haiku.git] / src / apps / icon-o-matic / shape / commands / TransformPointsCommand.cpp
blobe40f71e7974e06bccfcbd6654e6ded93ea0b4add
1 /*
2 * Copyright 2006, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
9 #include "TransformPointsCommand.h"
11 #include <new>
12 #include <stdio.h>
14 #include "ChannelTransform.h"
15 #include "VectorPath.h"
17 using std::nothrow;
19 // constructor
20 TransformPointsCommand::TransformPointsCommand(
21 TransformBox* box,
23 VectorPath* path,
24 const int32* indices,
25 const control_point* points,
26 int32 count,
28 BPoint pivot,
29 BPoint translation,
30 double rotation,
31 double xScale,
32 double yScale,
34 const char* name,
35 int32 nameIndex)
36 : TransformCommand(pivot,
37 translation,
38 rotation,
39 xScale,
40 yScale,
41 name,
42 nameIndex),
43 fTransformBox(box),
44 fPath(path),
45 fIndices(indices && count > 0 ?
46 new (nothrow) int32[count] : NULL),
47 fPoints(points && count > 0 ?
48 new (nothrow) control_point[count] : NULL),
49 fCount(count)
51 if (!fIndices || !fPoints)
52 return;
54 memcpy(fIndices, indices, fCount * sizeof(int32));
55 memcpy(fPoints, points, fCount * sizeof(control_point));
57 if (fTransformBox)
58 fTransformBox->AddListener(this);
61 // destructor
62 TransformPointsCommand::~TransformPointsCommand()
64 if (fTransformBox)
65 fTransformBox->RemoveListener(this);
67 delete[] fIndices;
68 delete[] fPoints;
71 // InitCheck
72 status_t
73 TransformPointsCommand::InitCheck()
75 return fPath && fIndices && fPoints ? TransformCommand::InitCheck()
76 : B_NO_INIT;
79 // #pragma mark -
81 // TransformBoxDeleted
82 void
83 TransformPointsCommand::TransformBoxDeleted(
84 const TransformBox* box)
86 if (fTransformBox == box) {
87 if (fTransformBox)
88 fTransformBox->RemoveListener(this);
89 fTransformBox = NULL;
93 // #pragma mark -
95 // _SetTransformation
96 status_t
97 TransformPointsCommand::_SetTransformation(
98 BPoint pivot, BPoint translation,
99 double rotation,
100 double xScale, double yScale) const
102 if (fTransformBox) {
103 fTransformBox->SetTransformation(pivot, translation,
104 rotation, xScale, yScale);
105 return B_OK;
109 ChannelTransform transform;
110 transform.SetTransformation(pivot, translation,
111 rotation, xScale, yScale);
112 // restore original points and apply transformation
113 for (int32 i = 0; i < fCount; i++) {
114 BPoint point = transform.Transform(fPoints[i].point);
115 BPoint pointIn = transform.Transform(fPoints[i].point_in);
116 BPoint pointOut = transform.Transform(fPoints[i].point_out);
117 if (!fPath->SetPoint(fIndices[i], point, pointIn, pointOut,
118 fPoints[i].connected))
119 return B_ERROR;
122 return B_OK;