andrey          Wed Nov 30 11:20:25 2005 EDT

  Added files:                 (Branch: PHP_5_1)
    /php-src/ext/mysqli/tests   bug35103.phpt 

  Modified files:              
    /php-src/ext/mysqli mysqli_api.c 
  Log:
  add a test case
  fix incorrect handling of unsigned bigint.
  optimize handling of unsigned int
  
  
http://cvs.php.net/diff.php/php-src/ext/mysqli/mysqli_api.c?r1=1.118.2.8&r2=1.118.2.9&ty=u
Index: php-src/ext/mysqli/mysqli_api.c
diff -u php-src/ext/mysqli/mysqli_api.c:1.118.2.8 
php-src/ext/mysqli/mysqli_api.c:1.118.2.9
--- php-src/ext/mysqli/mysqli_api.c:1.118.2.8   Wed Nov 30 10:26:39 2005
+++ php-src/ext/mysqli/mysqli_api.c     Wed Nov 30 11:20:22 2005
@@ -15,7 +15,7 @@
   | Author: Georg Richter <[EMAIL PROTECTED]>                                |
   +----------------------------------------------------------------------+
 
-  $Id: mysqli_api.c,v 1.118.2.8 2005/11/30 15:26:39 andrey Exp $ 
+  $Id: mysqli_api.c,v 1.118.2.9 2005/11/30 16:20:22 andrey Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -617,8 +617,7 @@
        zval                    *mysql_stmt;
        unsigned int    i;
        ulong                   ret;
-       int                             lval;
-       unsigned int    ulval;
+       unsigned int    uval;
        double                  dval;
        my_ulonglong    llval;
        
@@ -653,19 +652,24 @@
                                                    && 
(stmt->stmt->fields[i].flags & UNSIGNED_FLAG)) 
                                                {
                                                        /* unsigned int (11) */
-                                                       char tmp[12];
-                                                       memcpy (&ulval, 
stmt->result.buf[i].val, sizeof(lval));
-                                                       if (ulval > INT_MAX) {
-                                                               sprintf((char 
*)&tmp, "%u", ulval);
-                                                               
ZVAL_STRING(stmt->result.vars[i], tmp, 1);
-                                                       } else {
-                                                               memcpy(&lval, 
stmt->result.buf[i].val, sizeof(lval));
-                                                               
ZVAL_LONG(stmt->result.vars[i], lval);                                  
+                                                       uval= *(unsigned int *) 
stmt->result.buf[i].val;
+
+                                                       if (uval > INT_MAX) {
+                                                               char *tmp, *p;
+                                                               int j=10;
+                                                               tmp= 
emalloc(11);
+                                                               p= &tmp[9];
+                                                               do { 
+                                                                       *p-- = 
(uval % 10) + 48;
+                                                                       uval = 
uval / 10;                                                       
+                                                               } while (--j > 
0);
+                                                               tmp[10]= '\0';
+                                                               /* unsigned int 
> INT_MAX is 10 digis - ALWAYS */
+                                                               
ZVAL_STRINGL(stmt->result.vars[i], tmp, 10, 0);
+                                                               break;
                                                        }
-                                               } else {
-                                                       memcpy(&lval, 
stmt->result.buf[i].val, sizeof(lval));
-                                                       
ZVAL_LONG(stmt->result.vars[i], lval);
                                                }
+                                               ZVAL_LONG(stmt->result.vars[i], 
*(int *)stmt->result.buf[i].val);
                                                break;
                                        case IS_DOUBLE:
                                                memcpy(&dval, 
stmt->result.buf[i].val, sizeof(dval));
@@ -673,14 +677,21 @@
                                                break;
                                        case IS_STRING:
                                                if 
(stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_LONGLONG) {
-                                                       char tmp[50];
-                                                       memcpy (&llval, 
stmt->result.buf[i].val, sizeof(my_ulonglong));
-                                                       if (llval != 
(long)llval) {
+                                                       my_bool uns= 
(stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? 1:0;
+                                                       llval= *(my_ulonglong 
*) stmt->result.buf[i].val;
+#if SIZEOF_LONG==8  
+                                                       if (uns && llval > 
9223372036854775807L) {
+#elif SIZEOF_LONG==4
+                                                       if ((uns && llval > 
2147483647LL) || 
+                                                           (!uns && (( 
2147483647LL < (long long) llval) || (-2147483648LL > (long long) llval))))
+                                                       {
+#endif
+                                                               char tmp[22];
                                                                /* even though 
lval is declared as unsigned, the value
                                                                 * may be 
negative. Therefor we cannot use %llu and must
                                                                 * use %lld.
                                                                 */
-                                                               sprintf((char 
*)&tmp, "%lld", llval);
+                                                               sprintf((char 
*)&tmp, (stmt->stmt->fields[i].flags & UNSIGNED_FLAG)? "%llu":"%lld", llval);
                                                                
ZVAL_STRING(stmt->result.vars[i], tmp, 1);
                                                        } else {
                                                                
ZVAL_LONG(stmt->result.vars[i], llval);

http://cvs.php.net/co.php/php-src/ext/mysqli/tests/bug35103.phpt?r=1.1&p=1
Index: php-src/ext/mysqli/tests/bug35103.phpt
+++ php-src/ext/mysqli/tests/bug35103.phpt

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to