mathgl/mathgl-fix-overflow.patch

41 lines
1.5 KiB
Diff
Raw Normal View History

diff -r 9ad9a88a8e91 include/mgl2/base.h
--- include/mgl2/base.h Sun Apr 14 22:38:31 2013 +0100
+++ include/mgl2/base.h Sun Apr 14 22:42:46 2013 +0100
@@ -161,11 +161,14 @@
{ Create(a.nt, a.nl); memcpy(trig, a.trig, 6*nt*sizeof(short));
memcpy(line, a.line, 2*nl*sizeof(short)); return *this; }
};
+
+const int MGL_TEXTURE_COLOURS=512;
+
//-----------------------------------------------------------------------------
/// Structure for texture (color scheme + palette) representation
struct MGL_EXPORT mglTexture
{
- mglColor col[512]; ///< Colors itself
+ mglColor col[MGL_TEXTURE_COLOURS]; ///< Colors itself
long n; ///< Number of initial colors along u
char Sch[260]; ///< Color scheme used
@@ -179,6 +182,7 @@
void Set(const char *cols, int smooth=0,mreal alpha=1);
void Set(HCDT val, const char *cols);
void GetC(mreal u,mreal v,mglPnt &p) const;
+ size_t GetNumColours() { return MGL_TEXTURE_COLOURS;}
mglColor GetC(mreal u,mreal v=0) const;
inline bool IsSame(const mglTexture &t) const
{ return n==t.n && !memcmp(col,t.col,512*sizeof(mglColor)); }
diff -r 9ad9a88a8e91 src/base.cpp
--- src/base.cpp Sun Apr 14 22:38:31 2013 +0100
+++ src/base.cpp Sun Apr 14 22:42:46 2013 +0100
@@ -882,7 +882,8 @@
return i+j/255.;
// add new texture
mglTexture t;
- for(i=0;i<514;i++) t.col[i]=c;
+ size_t maxColours=t.GetNumColours();
+ for(i=0;i<maxColours;i++) t.col[i]=c;
MGL_PUSH(Txt,t,mutexTxt); return Txt.size()-1;
}
//-----------------------------------------------------------------------------