]> granicus.if.org Git - php/commitdiff
Move code out, that handles the actual structure to be used for the decoded
authorAndrey Hristov <andrey@php.net>
Mon, 17 Feb 2014 16:37:08 +0000 (18:37 +0200)
committerAndrey Hristov <andrey@php.net>
Mon, 17 Feb 2014 16:37:08 +0000 (18:37 +0200)
data. Will make it easier to add different structures

ext/mysqlnd/mysqlnd_ps.c
ext/mysqlnd/mysqlnd_result.c

index 8096cbbbd9d15f6305df710dce0a51c13f965128..fa2abc71d7499ce5f14c122e9ac1ebd04019870d 100644 (file)
@@ -104,6 +104,26 @@ MYSQLND_METHOD(mysqlnd_stmt, store_result)(MYSQLND_STMT * const s TSRMLS_DC)
        ret = result->m.store_result_fetch_data(conn, result, result->meta, TRUE TSRMLS_CC);
 
        if (PASS == ret) {
+               /* Overflow ? */
+               MYSQLND_RES_BUFFERED * set = result->stored_data;
+               if (set->row_count) {
+                       /* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
+                       if (set->row_count * result->meta->field_count * sizeof(zval *) > SIZE_MAX) {
+                               SET_OOM_ERROR(*conn->error_info);
+                               DBG_RETURN(NULL);
+                       }
+                       /* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux) */
+                       set->data = mnd_emalloc((size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
+                       if (!set->data) {
+                               SET_OOM_ERROR(*conn->error_info);
+                               DBG_RETURN(NULL);
+                       }
+                       memset(set->data, 0, (size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
+               }
+               /* Position at the first row */
+               set->data_cursor = set->data;
+
+
                /* libmysql API docs say it should be so for SELECT statements */
                stmt->upsert_status->affected_rows = stmt->result->stored_data->row_count;
 
index fbf8ea031cd9de917fcede7861ee743b86a5f2ab..944999b79caaa76aa236017687335ad7ca663b6b 100644 (file)
@@ -1155,6 +1155,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
                */
        }
        /* Overflow ? */
+#if 0
        if (set->row_count) {
                /* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
                if (set->row_count * meta->field_count * sizeof(zval *) > SIZE_MAX) {
@@ -1171,7 +1172,7 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
                }
                memset(set->data, 0, (size_t)(set->row_count * meta->field_count * sizeof(zval *)));
        }
-
+#endif
        MYSQLND_INC_CONN_STATISTIC_W_VALUE(conn->stats,
                                                                           binary_protocol? STAT_ROWS_BUFFERED_FROM_CLIENT_PS:
                                                                                                                STAT_ROWS_BUFFERED_FROM_CLIENT_NORMAL,
@@ -1203,9 +1204,6 @@ MYSQLND_METHOD(mysqlnd_res, store_result_fetch_data)(MYSQLND_CONN_DATA * const c
        if (ret == FAIL) {
                COPY_CLIENT_ERROR(set->error_info, row_packet->error_info);
        } else {
-               /* Position at the first row */
-               set->data_cursor = set->data;
-
                /* libmysql's documentation says it should be so for SELECT statements */
                conn->upsert_status->affected_rows = set->row_count;
        }
@@ -1255,7 +1253,27 @@ MYSQLND_METHOD(mysqlnd_res, store_result)(MYSQLND_RES * result,
                        SET_OOM_ERROR(*conn->error_info);
                }
                DBG_RETURN(NULL);
+       } else {
+       /* Overflow ? */
+               MYSQLND_RES_BUFFERED * set = result->stored_data;
+               if (set->row_count) {
+                       /* don't try to allocate more than possible - mnd_XXalloc expects size_t, and it can have narrower range than uint64_t */
+                       if (set->row_count * result->meta->field_count * sizeof(zval *) > SIZE_MAX) {
+                               SET_OOM_ERROR(*conn->error_info);
+                               DBG_RETURN(NULL);
+                       }
+                       /* if pecalloc is used valgrind barks gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036] (SUSE Linux) */
+                       set->data = mnd_emalloc((size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
+                       if (!set->data) {
+                               SET_OOM_ERROR(*conn->error_info);
+                               DBG_RETURN(NULL);
+                       }
+                       memset(set->data, 0, (size_t)(set->row_count * result->meta->field_count * sizeof(zval *)));
+               }
+               /* Position at the first row */
+               set->data_cursor = set->data;
        }
+
        /* libmysql's documentation says it should be so for SELECT statements */
        conn->upsert_status->affected_rows = result->stored_data->row_count;