Re: Suspect code in magick/floats.c

Ian Zimmerman <[email protected]> Sat, 27 Oct 2012 20:50:37 -0700
Newsgroups gmane.comp.video.graphicsmagick.tools
Message-ID <[email protected]>
Here's my preferred fix:

diff --git a/magick/floats.c b/magick/floats.c
index 1dc06ee..86a800d 100644
--- a/magick/floats.c
+++ b/magick/floats.c
@@ -33,6 +33,7 @@ int _Gm_convert_fp16_to_fp32 (const fp_16bits *fp16, float *fp32)
   unsigned int   little_endian = 1;
   unsigned char *src;
   unsigned char *dst;
+  fp_16bits zero;
 
 #ifdef DEBUG32
   /* Debugging variables */
@@ -58,7 +59,7 @@ int _Gm_convert_fp16_to_fp32 (const fp_16bits *fp16, float *fp32)
   new_m3 = new_m2 = new_m1 = m2 = m1 = 0;
 
   little_endian = *((unsigned char *)&little_endian) & '1';
-  if ((int)*fp16 != 0)
+  if (memcmp(zero, src, 2) != 0)
     {
       if (little_endian)
 	{
@@ -478,6 +479,7 @@ int _Gm_convert_fp24_to_fp32 (const fp_24bits *fp24, float *fp32, const int mode
   /* unsigned char *mp; */
   unsigned char *src;
   unsigned char *dst;
+  fp_24bits zero;
 
 #ifdef DEBUG32
   int      i, j, k, bit;
@@ -504,7 +506,7 @@ int _Gm_convert_fp24_to_fp32 (const fp_24bits *fp24, float *fp32, const int mode
   /* new_mant = mant = 0; */
   new_m3 = new_m2 = new_m1 = m2 = m1 = 0;
 
-  if ((int)*fp24 == 0)
+  if (memcmp(zero, src, 3) == 0)
     {
       *dst = 0;
       *(dst + 1) = 0;


-- 
Ian Zimmerman
gpg public key: 1024D/C6FF61AD
fingerprint: 66DC D68F 5C1B 4D71 2EE5  BD03 8A00 786C C6FF 61AD
http://www.gravatar.com/avatar/c66875cda51109f76c6312f4d4743d1e.png
Rule 420: All persons more than eight miles high to leave the court.

------------------------------------------------------------------------------
WINDOWS 8 is here. 
Millions of people.  Your app in 30 days.
Visit The Windows 8 Center at Sourceforge for all your go to resources.
http://windows8center.sourceforge.net/
join-generation-app-and-make-money-coding-fast/