| | @@ -125,17 +125,23 @@ |
| 125 | 125 | ** function, a string is considered empty if it contains no characters |
| 126 | 126 | ** -OR- it contains only NUL characters. |
| 127 | 127 | */ |
| 128 | 128 | static int count_lines( |
| 129 | 129 | const char *z, |
| 130 | | - int n |
| 130 | + int n, |
| 131 | + int *pnLine |
| 131 | 132 | ){ |
| 132 | 133 | int nLine; |
| 133 | 134 | const char *zNL, *z2; |
| 134 | | - for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){} |
| 135 | | - if( z2[0]!='\0' ) nLine++; |
| 136 | | - return nLine; |
| 135 | + for(nLine=0, z2=z; (zNL = strchr(z2,'\n'))!=0; z2=zNL+1, nLine++){} |
| 136 | + if( z2[0]!='\0' ){ |
| 137 | + nLine++; |
| 138 | + do{ z2++; }while( z2[0] ); |
| 139 | + } |
| 140 | + if( n!=(int)(z2-z) ) return 0; |
| 141 | + if( pnLine ) *pnLine = nLine; |
| 142 | + return 1; |
| 137 | 143 | } |
| 138 | 144 | |
| 139 | 145 | /* |
| 140 | 146 | ** Return an array of DLine objects containing a pointer to the |
| 141 | 147 | ** start of each line and a hash of that line. The lower |
| | @@ -160,25 +166,23 @@ |
| 160 | 166 | int nLine, i, k, nn, s, x; |
| 161 | 167 | unsigned int h, h2; |
| 162 | 168 | DLine *a; |
| 163 | 169 | const char *zNL; |
| 164 | 170 | |
| 165 | | - nLine = count_lines(z, n); |
| 171 | + if( count_lines(z, n, &nLine)==0 ){ |
| 172 | + return 0; |
| 173 | + } |
| 166 | 174 | assert( nLine>0 || z[0]=='\0' ); |
| 167 | 175 | a = fossil_malloc( sizeof(a[0])*nLine ); |
| 168 | 176 | memset(a, 0, sizeof(a[0])*nLine); |
| 169 | 177 | if( nLine==0 ){ |
| 170 | | - if( fossil_strchr(z,n,'\0')!=0 ){ |
| 171 | | - fossil_free(a); |
| 172 | | - return 0; |
| 173 | | - } |
| 174 | 178 | *pnLine = 0; |
| 175 | 179 | return a; |
| 176 | 180 | } |
| 177 | 181 | i = 0; |
| 178 | 182 | do{ |
| 179 | | - zNL = fossil_strchr(z,n,'\n'); |
| 183 | + zNL = strchr(z,'\n'); |
| 180 | 184 | if( zNL==0 ) zNL = z+n; |
| 181 | 185 | nn = (int)(zNL - z); |
| 182 | 186 | if( nn>LENGTH_MASK ){ |
| 183 | 187 | fossil_free(a); |
| 184 | 188 | return 0; |
| | @@ -196,14 +200,10 @@ |
| 196 | 200 | if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){ |
| 197 | 201 | int numws = 0; |
| 198 | 202 | while( s<k && fossil_isspace(z[s]) ){ s++; } |
| 199 | 203 | for(h=0, x=s; x<k; x++){ |
| 200 | 204 | char c = z[x]; |
| 201 | | - if( c=='\0' ){ |
| 202 | | - fossil_free(a); |
| 203 | | - return 0; |
| 204 | | - } |
| 205 | 205 | if( fossil_isspace(c) ){ |
| 206 | 206 | ++numws; |
| 207 | 207 | }else{ |
| 208 | 208 | h += c; |
| 209 | 209 | h *= 0x9e3779b1; |
| | @@ -210,16 +210,11 @@ |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | k -= numws; |
| 213 | 213 | }else{ |
| 214 | 214 | for(h=0, x=s; x<k; x++){ |
| 215 | | - char c = z[x]; |
| 216 | | - if( c=='\0' ){ |
| 217 | | - fossil_free(a); |
| 218 | | - return 0; |
| 219 | | - } |
| 220 | | - h += c; |
| 215 | + h += z[x]; |
| 221 | 216 | h *= 0x9e3779b1; |
| 222 | 217 | } |
| 223 | 218 | } |
| 224 | 219 | a[i].indent = s; |
| 225 | 220 | a[i].h = h = (h<<LENGTH_MASK_SZ) | (k-s); |
| 226 | 221 | |