Skip to content

Commit

Permalink
fix #4985:
Browse files Browse the repository at this point in the history
out of bounds access when copying float3 to float4
  • Loading branch information
abma committed Nov 1, 2015
1 parent 9b75b21 commit 88c7414
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rts/Rendering/GL/Light.h
Expand Up @@ -59,13 +59,13 @@ namespace GL {
const float3& GetSpecularDecayRate() const { return specularDecayRate; }
const float3& GetDecayFunctionType() const { return decayFunctionType; }

void SetPosition(const float array[3]) { position = array; }
void SetPosition(const float array[3]) { position.fromFloat3(array); }
void SetDirection(const float array[3]) { direction = array; }
void SetTrackPosition(const float3* pos) { trackPosition = pos; }
void SetTrackDirection(const float3* dir) { trackDirection = dir; }
void SetAmbientColor(const float array[3]) { ambientColor = array; }
void SetDiffuseColor(const float array[3]) { diffuseColor = array; }
void SetSpecularColor(const float array[3]) { specularColor = array; }
void SetAmbientColor(const float array[3]) { ambientColor.fromFloat3(array); }
void SetDiffuseColor(const float array[3]) { diffuseColor.fromFloat3(array); }
void SetSpecularColor(const float array[3]) { specularColor.fromFloat3(array); }
void SetIntensityWeight(const float array[3]) { intensityWeight = array; }
void SetAttenuation(const float array[3]) { attenuation = array; }
void SetAmbientDecayRate(const float array[3]) { ambientDecayRate = array; }
Expand Down
6 changes: 6 additions & 0 deletions rts/System/float4.h
Expand Up @@ -32,6 +32,12 @@ struct float4 : public float3
return *this;
}

inline void fromFloat3 (const float f[3]) {
x = f[0];
y = f[1];
z = f[2];
}

inline float4& operator= (const float3& f) {
x = f.x;
y = f.y;
Expand Down

1 comment on commit 88c7414

@abma
Copy link
Contributor Author

@abma abma commented on 88c7414 Nov 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use arrays as parameters? it seems they get converted to pointers:

http://stackoverflow.com/questions/1328223/sizeof-array-passed-as-parameter

shouldn't be a reference / float3& be used as parameter then?

or (x, y, z) !?

Please sign in to comment.