So I took a look at False 1 4 V512 A call of the 'memcpy' function will lead to overflow of the buffer '& x'. code pstypes.h 131 False
I can either fix it the easy way and just expand the memcpy into three assignments or fix it properly and convert vertex[/tt] to using vec3ds. I started to do the conversion, but when I realized that this is going to touch most of the graphics code I figured I should ask for an opinion? Do it right or fix it quick? The layout of this struct is abused all over the code in similar fashion os the one the PVS-Studio is complaining about.
Index: code/globalincs/pstypes.h
===================================================================
--- code/globalincs/pstypes.h (revision 7609)
+++ code/globalincs/pstypes.h (working copy)
@@ -81,6 +81,9 @@
struct {
float x,y,z;
} xyz;
+ struct {
+ float x,y,w;
+ } xyw;
float a1d[3];
};
inline void operator= (vertex&vert);
@@ -89,7 +92,7 @@
bool operator == (const vec3d &other);
} vec3d;
-inline bool vec3d::operator == (const vec3d &other)
+inline bool vec3d::operator== (const vec3d &other)
{
return ( (a1d[0] == other.a1d[0]) && (a1d[1] == other.a1d[1]) && (a1d[2] == other.a1d[2]) );
}
@@ -114,21 +117,28 @@
typedef struct uv_pair {
float u,v;
+
+ bool operator==(const uv_pair &other);
} uv_pair;
+bool uv_pair::operator==(const uv_pair &other)
+{
+ return (u == other.u) && (v == other.v);
+}
+
// Used to store rotated points for mines.
// Has flag to indicate if projected.
typedef struct vertex {
- float x, y, z; // world space position
- float sx, sy, sw; // screen space position (sw == 1/z)
- float u, v; // texture position
+ vec3d world_pos; // world space position
+ vec3d screen_pos; // screen space position (sw == 1/z)
+ uv_pair uv; // texture position
ubyte r, g, b, a; // color. Use b for darkening;
ubyte spec_r, spec_g, spec_b, spec_a; //specular highlights -Bobboau
ubyte codes; // what sides of view pyramid this point is on/off. 0 = Inside view pyramid.
ubyte flags; // Projection flags. Indicates whether it is projected or not or if projection overflowed.
ubyte pad[2]; // pad structure to be 4 byte aligned.
- void operator=(vec3d&vec) {
- memcpy(&x,&vec, sizeof(vec3d));
+ void operator=(vec3d& vec) {
+ memcpy(&world_pos,&vec, sizeof(vec3d));
}
bool operator == (const vertex &other);
@@ -137,17 +147,17 @@
inline bool vertex::operator == (const vertex &other)
{
// NOTE: this is checking position and uv only!
- return ( (x == other.x) && (y == other.y) && (z == other.z)
- && (u == other.u) && (v == other.v) );
+ return ( ( world_pos == other.world_pos )
+ && (uv == other.uv) );
}
inline void vec3d::operator= (vertex&vert) {
- memcpy(this,&vert.x,sizeof(vec3d));
+ memcpy(this,&vert.world_pos,sizeof(vec3d));
}
//set the vector to the vertex screen position
inline void vec3d::set_screen_vert(vertex&vert) {
- memcpy(this,&vert.sx,sizeof(vec3d));
+ memcpy(this,&vert.screen_pos,sizeof(vec3d));
}
//def_list