Author: adrianl
Date: Fri Jan 23 18:57:14 2009
New Revision: 6214

URL: http://source.netsurf-browser.org?rev=6214&view=rev
Log:
Fix handling of max -ve numbers

Modified:
    trunk/libcss/src/utils/utils.h
    trunk/libcss/test/data/number/number.dat
    trunk/libcss/test/number.c

Modified: trunk/libcss/src/utils/utils.h
URL: 
http://source.netsurf-browser.org/trunk/libcss/src/utils/utils.h?rev=6214&r1=6213&r2=6214&view=diff
==============================================================================
--- trunk/libcss/src/utils/utils.h (original)
+++ trunk/libcss/src/utils/utils.h Fri Jan 23 18:57:14 2009
@@ -79,7 +79,7 @@
                if (ptr[0] < '0' || '9' < ptr[0])
                        break;
 
-               /* Clamp to a max of 2^22 - 1 */
+               /* Prevent overflow of 'intpart'; proper clamping below */
                if (intpart < (1 << 22)) {
                        intpart *= 10;
                        intpart += ptr[0] - '0';
@@ -113,16 +113,33 @@
                }
        }
 
-       /* If the intpart is larger than we can represent, 
-        * then clamp to the maximum value we can store. */
-       if (intpart >= (1 << 21)) {
-               fracpart = (1 << 10) - 1;
-               intpart = (1 << 21) - 1;
+       *consumed = ptr - string->data;
+
+       if (sign > 0) {
+               /* If the result is larger than we can represent,
+                * then clamp to the maximum value we can store. */
+               if (intpart >= (1 << 21)) {
+                       intpart = (1 << 21) - 1;
+                       fracpart = (1 << 10) - 1;
+               }
+       }
+       else {
+               /* If the negated result is smaller than we can represent
+                * then clamp to the minimum value we can store. */
+               if (intpart >= (1 << 21)) {
+                       intpart = -(1 << 21);
+                       fracpart = 0;
+               }
+               else {
+                       intpart = -intpart;
+                       if (fracpart) {
+                               fracpart = (1 << 10) - fracpart;
+                               intpart--;
+                       }
+               }
        }
 
-       *consumed = ptr - string->data;
-
-       return FMULI(((intpart << 10) | fracpart), sign);
+       return (intpart << 10) | fracpart;
 }
 
 static inline bool isDigit(uint8_t c)

Modified: trunk/libcss/test/data/number/number.dat
URL: 
http://source.netsurf-browser.org/trunk/libcss/test/data/number/number.dat?rev=6214&r1=6213&r2=6214&view=diff
==============================================================================
--- trunk/libcss/test/data/number/number.dat (original)
+++ trunk/libcss/test/data/number/number.dat Fri Jan 23 18:57:14 2009
@@ -64,17 +64,16 @@
 -2097151.000
 #reset
 
-# TODO: should these next two not result in INT_MIN?
 #data
 -2097152
 #expected
--2097151.999
+-2097152
 #reset
 
 #data
 -2097153
 #expected
--2097151.999
+-2097152
 #reset
 
 #data

Modified: trunk/libcss/test/number.c
URL: 
http://source.netsurf-browser.org/trunk/libcss/test/number.c?rev=6214&r1=6213&r2=6214&view=diff
==============================================================================
--- trunk/libcss/test/number.c (original)
+++ trunk/libcss/test/number.c Fri Jan 23 18:57:14 2009
@@ -127,7 +127,7 @@
 
 void print_fixed(char *buf, size_t len, fixed f)
 {
-#define ABS(x) ((x) < 0 ? -(x) : (x))
+#define ABS(x) (uint32_t)((x) < 0 ? -(x) : (x))
        uint32_t uintpart = FIXTOINT(ABS(f));
        /* + 500 to ensure round to nearest (division will truncate) */
        uint32_t fracpart = ((ABS(f) & 0x3ff) * 1000 + 500) / (1 << 10);


_______________________________________________
netsurf-commits mailing list
[email protected]
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to