@@ -2047,10 +2047,10 @@ PHP_FUNCTION(fgetcsv)
2047
2047
2048
2048
PHPAPI void php_fgetcsv (php_stream * stream , char delimiter , char enclosure , int escape_char , size_t buf_len , char * buf , zval * return_value ) /* {{{ */
2049
2049
{
2050
- char * temp , * tptr , * bptr , * line_end , * limit ;
2050
+ char * temp , * bptr , * line_end , * limit ;
2051
2051
size_t temp_len , line_end_len ;
2052
2052
int inc_len ;
2053
- bool first_field = 1 ;
2053
+ bool first_field = true ;
2054
2054
2055
2055
ZEND_ASSERT ((escape_char >= 0 && escape_char <= UCHAR_MAX ) || escape_char == PHP_CSV_NO_ESCAPE );
2056
2056
@@ -2062,9 +2062,8 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2062
2062
/* Strip trailing space from buf, saving end of line in case required for enclosure field */
2063
2063
2064
2064
bptr = buf ;
2065
- tptr = (char * )php_fgetcsv_lookup_trailing_spaces (buf , buf_len );
2066
- line_end_len = buf_len - (size_t )(tptr - buf );
2067
- line_end = limit = tptr ;
2065
+ line_end = limit = (char * )php_fgetcsv_lookup_trailing_spaces (buf , buf_len );
2066
+ line_end_len = buf_len - (size_t )(limit - buf );
2068
2067
2069
2068
/* reserve workspace for building each individual field */
2070
2069
temp_len = buf_len ;
@@ -2078,8 +2077,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2078
2077
2079
2078
do {
2080
2079
char * comp_end , * hunk_begin ;
2081
-
2082
- tptr = temp ;
2080
+ char * tptr = temp ;
2083
2081
2084
2082
inc_len = (bptr < limit ? (* bptr == '\0' ? 1 : php_mblen (bptr , limit - bptr )): 0 );
2085
2083
if (inc_len == 1 ) {
@@ -2096,7 +2094,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2096
2094
add_next_index_null (return_value );
2097
2095
break ;
2098
2096
}
2099
- first_field = 0 ;
2097
+ first_field = false ;
2100
2098
/* 2. Read field, leaving bptr pointing at start of next field */
2101
2099
if (inc_len != 0 && * bptr == enclosure ) {
2102
2100
int state = 0 ;
@@ -2122,10 +2120,6 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2122
2120
ZEND_FALLTHROUGH ;
2123
2121
2124
2122
case 0 : {
2125
- char * new_buf ;
2126
- size_t new_len ;
2127
- char * new_temp ;
2128
-
2129
2123
if (hunk_begin != line_end ) {
2130
2124
memcpy (tptr , hunk_begin , bptr - hunk_begin );
2131
2125
tptr += (bptr - hunk_begin );
@@ -2138,7 +2132,11 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2138
2132
2139
2133
if (stream == NULL ) {
2140
2134
goto quit_loop_2 ;
2141
- } else if ((new_buf = php_stream_get_line (stream , NULL , 0 , & new_len )) == NULL ) {
2135
+ }
2136
+
2137
+ size_t new_len ;
2138
+ char * new_buf = php_stream_get_line (stream , NULL , 0 , & new_len );
2139
+ if (!new_buf ) {
2142
2140
/* we've got an unterminated enclosure,
2143
2141
* assign all the data from the start of
2144
2142
* the enclosure to end of data to the
@@ -2150,8 +2148,9 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int
2150
2148
RETVAL_FALSE ;
2151
2149
goto out ;
2152
2150
}
2151
+
2153
2152
temp_len += new_len ;
2154
- new_temp = erealloc (temp , temp_len );
2153
+ char * new_temp = erealloc (temp , temp_len );
2155
2154
tptr = new_temp + (size_t )(tptr - temp );
2156
2155
temp = new_temp ;
2157
2156
0 commit comments