Re: cvs: php4 /ext/mssql php_mssql.c php_mssql.h

From: Date: Wed, 15 May 2002 07:56:26 +0000
Subject: Re: cvs: php4 /ext/mssql php_mssql.c php_mssql.h
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11924@lists.php.net to get a copy of this message
as i assume you tested the code i wonder what i am missing... Example Change:
                                hashed_details_length = Z_STRLEN_PP(yyhost)+5+3;
-                               hashed_details = (char *) emalloc(hashed_details_length+1);
+                               hashed_details = (char *) emalloc(hashed_details_length);
sprintf(hashed_details,"mssql_%s__",Z_STRVAL_PP(yyhost));
Z_STRLEN_PP stores the length of the string *not* including terminating NULL as you can see in the ZVAL_STRING constructor: #define ZVAL_STRING(z, s, duplicate) { \
                char *__s=(s);                                  \
                (z)->value.str.len = strlen(__s);       \
                (z)->value.str.val = (duplicate?estrndup(__s, (z)->value.str.len):__s); \
                (z)->type = IS_STRING;          \
        }
say host is localhost -> Z_STRLEN_PP('localhost') = 9 -> hashed_details_length = 17 hashed_details = 'mssql_localhost__' + \0 => buffer needed = strlen('mssql_localhost__') + 1 = 18 hence you write one byte after the buffer... msrcus At 01:57 15.05.2002, Frank M. Kromann wrote:
fmk             Tue May 14 19:57:44 2002 EDT
Modified files:
    /php4/ext/mssql     php_mssql.c php_mssql.h
Log: Fixing hanfling of data type REAL. Remove extra bytes allocated by emalloc calls Index: php4/ext/mssql/php_mssql.c diff -u php4/ext/mssql/php_mssql.c:1.81 php4/ext/mssql/php_mssql.c:1.82
--- php4/ext/mssql/php_mssql.c:1.81     Thu May  9 16:37:43 2002
+++ php4/ext/mssql/php_mssql.c Tue May 14 19:57:41 2002 @@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: php_mssql.c,v 1.81 2002/05/09 20:37:43 fmk Exp $ */ +/* $Id: php_mssql.c,v 1.82 2002/05/14 23:57:41 fmk Exp $ */ #ifdef COMPILE_DL_MSSQL #define HAVE_MSSQL 1 @@ -305,6 +305,7 @@
        REGISTER_LONG_CONSTANT("SQLINT4",SQLINT4, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SQLBIT",SQLBIT, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SQLFLT8",SQLFLT8, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("SQLFLTN",SQLFLTN, CONST_CS | CONST_PERSISTENT);
        /* END MSSQL data types for mssql_sp_bind */
        return SUCCESS;
@@ -373,7 +374,7 @@
                case 0: /* defaults */
                        host=user=passwd=NULL;
                        hashed_details_length=5+3;
-                       hashed_details = (char *) emalloc(hashed_details_length+1);
+                       hashed_details = (char *) emalloc(hashed_details_length);
                        strcpy(hashed_details,"mssql___");
                        break;
                case 1: {
@@ -386,7 +387,7 @@
                                host = Z_STRVAL_PP(yyhost);
                                user=passwd=NULL;
                                hashed_details_length = Z_STRLEN_PP(yyhost)+5+3;
-                               hashed_details = (char *) emalloc(hashed_details_length+1);
+                               hashed_details = (char *) emalloc(hashed_details_length);
sprintf(hashed_details,"mssql_%s__",Z_STRVAL_PP(yyhost));
                        }
                        break;
@@ -402,7 +403,7 @@
                                user = Z_STRVAL_PP(yyuser);
                                passwd=NULL;
                                hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+5+3;
-                               hashed_details = (char *) emalloc(hashed_details_length+1);
+                               hashed_details = (char *) emalloc(hashed_details_length);
sprintf(hashed_details,"mssql_%s_%s_",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser));
                        }
                        break;
@@ -419,7 +420,7 @@
                                user = Z_STRVAL_PP(yyuser);
                                passwd = Z_STRVAL_PP(yypasswd);
                                hashed_details_length = Z_STRLEN_PP(yyhost)+Z_STRLEN_PP(yyuser)+Z_STRLEN_PP(yypasswd)+5+3;
-                               hashed_details = (char *) emalloc(hashed_details_length+1);
+                               hashed_details = (char *) emalloc(hashed_details_length);
sprintf(hashed_details,"mssql_%s_%s_%s",Z_STRVAL_PP(yyhost),Z_STRVAL_PP(yyuser),Z_STRVAL_PP(yypasswd)); /* SAFE */
                        }
                        break;
@@ -442,7 +443,7 @@
        dbprocerrhandle(mssql.login, (DBERRHANDLE_PROC) php_mssql_error_handler);
        dbprocmsghandle(mssql.login, (DBMSGHANDLE_PROC) php_mssql_message_handler);
-       if (MS_SQL_G(secure_connection)){
+       if (MS_SQL_G(secure_connection) == 1){
                DBSETLSECURE(mssql.login);
        }
        else {
@@ -778,11 +779,14 @@
                        Z_TYPE_P(result) = IS_STRING;
                        break;
                }
-               case SQLFLT8: {
-                       Z_DVAL_P(result) = (double) floatcol(offset);
+               case SQLFLT4:
+                       Z_DVAL_P(result) = (double) floatcol4(offset);
+                       Z_TYPE_P(result) = IS_DOUBLE;
+                       break;
+               case SQLFLT8:
+                       Z_DVAL_P(result) = (double) floatcol8(offset);
                        Z_TYPE_P(result) = IS_DOUBLE;
                        break;
-               }
                case SQLVARBINARY:
                case SQLBINARY:
                case SQLIMAGE: {
@@ -790,7 +794,7 @@
                        unsigned char *res_buf;
                        int res_length = dbdatlen(mssql_ptr->link, offset);
-                       res_buf = (unsigned char *) emalloc(res_length + 1);
+                       res_buf = (unsigned char *) emalloc(res_length);
                        bin = ((DBBINARY *)dbdata(mssql_ptr->link, offset));
                        memcpy(res_buf,bin,res_length);
                        res_buf[res_length] = '\0';
@@ -811,13 +815,13 @@
                                        if (column_type == SQLDATETIM4) res_length += 14;
                                        if (column_type == SQLDATETIME) res_length += 10;
-                                       res_buf = (unsigned char *) emalloc(res_length + 1);
+                                       res_buf = (unsigned char *) emalloc(res_length);
                                        res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR,res_buf,-1);
                                } else {
                                        dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
                                        res_length = 19;
-                                       res_buf = (unsigned char *) emalloc(res_length + 1);
+                                       res_buf = (unsigned char *) emalloc(res_length);
                                        sprintf(res_buf, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second);
                                }
@@ -846,7 +850,7 @@
                unsigned char *res_buf;
                int res_length = dbdatlen(mssql_ptr->link, offset);
-               res_buf = (unsigned char *) emalloc(res_length + 1);
+               res_buf = (unsigned char *) emalloc(res_length);
                bin = ((DBBINARY *)dbdata(mssql_ptr->link, offset));
                memcpy(res_buf, bin, res_length);
                res_buf[res_length] = '\0';
@@ -864,14 +868,14 @@
                        if (column_type == SQLDATETIM4) res_length += 14;
                        if (column_type == SQLDATETIME) res_length += 10;
-                       res_buf = (unsigned char *) emalloc(res_length + 1);
-                       res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR,res_buf,-1);
+                       res_buf = (unsigned char *) emalloc(res_length);
+                       res_length = dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR, res_buf, -1);
                } else {
                        dbdatecrack(mssql_ptr->link, &dateinfo, (DBDATETIME *) dbdata(mssql_ptr->link,offset));
                        res_length = 19;
-                       res_buf = (unsigned char *) emalloc(res_length + 1);
+                       res_buf = (unsigned char *) emalloc(res_length);
                        sprintf(res_buf, "%d-%02d-%02d %02d:%02d:%02d" , dateinfo.year, dateinfo.month, dateinfo.day, dateinfo.hour, dateinfo.minute, dateinfo.second);
                }
@@ -1881,6 +1885,7 @@
                switch (type)   {
                        case SQLFLT8:
+                       case SQLFLTN:
                                convert_to_double_ex(var);
                                value=(LPBYTE)(&Z_DVAL_PP(var));
                                break;
@@ -2024,6 +2029,7 @@
                                                                break;
                                                        case SQLFLT8:
+                                                       case SQLFLTN:
convert_to_double_ex(&bind->zval); Z_DVAL_P(bind->zval)=*((double *)(dbretdata(mssql_ptr->link,i)));
                                                                break;
Index: php4/ext/mssql/php_mssql.h diff -u php4/ext/mssql/php_mssql.h:1.21 php4/ext/mssql/php_mssql.h:1.22
--- php4/ext/mssql/php_mssql.h:1.21     Thu May  9 16:37:45 2002
+++ php4/ext/mssql/php_mssql.h Tue May 14 19:57:43 2002 @@ -17,7 +17,7 @@ */ -/* $Id: php_mssql.h,v 1.21 2002/05/09 20:37:45 fmk Exp $ */ +/* $Id: php_mssql.h,v 1.22 2002/05/14 23:57:43 fmk Exp $ */ #ifndef PHP_MSSQL_H #define PHP_MSSQL_H @@ -41,7 +41,8 @@ #define tinyintcol(i) ((int) *(DBTINYINT *) dbdata(mssql_ptr->link,i)) #define anyintcol(j) (coltype(j)==SQLINT4?intcol(j):(coltype(j)==SQLINT2?smallintcol(j):tinyintcol(j))) #define charcol(i) ((DBCHAR *) dbdata(mssql_ptr->link,i)) -#define floatcol(i) ((float) *(DBFLT8 *) dbdata(mssql_ptr->link,i)) +#define floatcol4(i) ((float) *(DBFLT4 *) dbdata(mssql_ptr->link,i)) +#define floatcol8(i) ((float) *(DBFLT8 *) dbdata(mssql_ptr->link,i)) #ifdef ZTS #include "TSRM.h" -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.cvs (#11924) next »