vfs: check userland buffers before reading them.
[haiku.git] / src / apps / icon-o-matic / Util.cpp
blobc7a84b47bd8cdb86a4e7d783aa16f06c47599f5a
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 "Util.h"
11 #include <new>
13 #include "AddPathsCommand.h"
14 #include "AddStylesCommand.h"
15 #include "PathContainer.h"
16 #include "Style.h"
17 #include "StyleContainer.h"
18 #include "VectorPath.h"
20 using std::nothrow;
22 // new_style
23 void
24 new_style(rgb_color color, StyleContainer* container,
25 Style** style, AddStylesCommand** command)
27 *style = new (nothrow) Style(color);
28 if (*style) {
29 Style* styles[1];
30 styles[0] = *style;
31 *command = new (nothrow) AddStylesCommand(
32 container, styles, 1,
33 container->CountStyles());
34 if (*command == NULL) {
35 delete *style;
36 *style = NULL;
38 } else {
39 *command = NULL;
43 // new_path
44 void
45 new_path(PathContainer* container, VectorPath** path,
46 AddPathsCommand** command, VectorPath* other)
48 if (other)
49 *path = new (nothrow) VectorPath(*other);
50 else
51 *path = new (nothrow) VectorPath();
53 if (*path) {
54 VectorPath* paths[1];
55 paths[0] = *path;
56 int32 insertIndex = other ? container->IndexOf(other) + 1
57 : container->CountPaths();
58 *command = new (nothrow) AddPathsCommand(
59 container, paths, 1, true, insertIndex);
60 if (*command == NULL) {
61 delete *path;
62 *path = NULL;
64 } else {
65 *command = NULL;