Skip to content

Commit 325638a

Browse files
committed
amend pointer arithmetic (by @xlz), protect internals (by @christiankerl)
1 parent b459d26 commit 325638a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

examples/protonect/include/libfreenect2/frame_listener.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
namespace libfreenect2
3535
{
3636

37-
struct LIBFREENECT2_API Frame
37+
class LIBFREENECT2_API Frame
3838
{
39+
public:
3940
enum Type
4041
{
4142
Color = 1,
@@ -46,22 +47,28 @@ struct LIBFREENECT2_API Frame
4647
uint32_t timestamp;
4748
uint32_t sequence;
4849
size_t width, height, bytes_per_pixel;
49-
unsigned char* rawdata;
5050
unsigned char* data;
5151

5252
Frame(size_t width, size_t height, size_t bytes_per_pixel) :
5353
width(width),
5454
height(height),
5555
bytes_per_pixel(bytes_per_pixel)
5656
{
57-
rawdata = new unsigned char[width * height * bytes_per_pixel + 128];
58-
data = (unsigned char*)((unsigned long long)(rawdata+64) & (unsigned long long)(0xFFFFFFFFFFFFFFC0ULL));
57+
const size_t alignment = 64;
58+
size_t space = width * height * bytes_per_pixel + alignment;
59+
rawdata = new unsigned char[space];
60+
uintptr_t ptr = reinterpret_cast<uintptr_t>(rawdata);
61+
uintptr_t aligned = (ptr - 1u + alignment) & -alignment;
62+
data = reinterpret_cast<unsigned char *>(aligned);
5963
}
6064

6165
~Frame()
6266
{
6367
delete[] rawdata;
6468
}
69+
70+
protected:
71+
unsigned char* rawdata;
6572
};
6673

6774
class LIBFREENECT2_API FrameListener

0 commit comments

Comments
 (0)