Fossil SCM

Further improve clarity.

mistachkin 2016-10-03 23:18 UTC binDiffFix
Commit 11e2c6e611d9caca1b21380fbfb86c568afc835a
1 file changed +8 -6
+8 -6
--- src/diff.c
+++ src/diff.c
@@ -119,20 +119,22 @@
119119
};
120120
121121
/*
122122
** Count the number of lines in the input string. Include the last line
123123
** in the count even if it lacks the \n terminator. If an empty string
124
-** is specified, the number of lines is zero.
124
+** is specified, the number of lines is zero. For the purposes of this
125
+** function, a string is considered empty if it contains no characters
126
+** -OR- it contains only NUL characters.
125127
*/
126128
static int count_lines(
127129
const char *z,
128130
int n
129131
){
130132
int nLine;
131133
const char *zNL, *z2;
132134
for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
133
- if( z2[0]!=0 ) nLine++;
135
+ if( z2[0]!='\0' ) nLine++;
134136
return nLine;
135137
}
136138
137139
/*
138140
** Return an array of DLine objects containing a pointer to the
@@ -159,11 +161,11 @@
159161
unsigned int h, h2;
160162
DLine *a;
161163
const char *zNL;
162164
163165
nLine = count_lines(z, n);
164
- assert( nLine>0 || z[0]==0 );
166
+ assert( nLine>0 || z[0]=='\0' );
165167
a = fossil_malloc( sizeof(a[0])*nLine );
166168
memset(a, 0, sizeof(a[0])*nLine);
167169
if( nLine==0 ){
168170
if( fossil_strchr(z,n,'\0')!=0 ){
169171
fossil_free(a);
@@ -193,11 +195,11 @@
193195
}
194196
if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
195197
int numws = 0;
196198
while( s<k && fossil_isspace(z[s]) ){ s++; }
197199
for(h=0, x=s; x<k; x++){
198
- if( z[x]==0 ){
200
+ if( z[x]=='\0' ){
199201
fossil_free(a);
200202
return 0;
201203
}
202204
if( fossil_isspace(z[x]) ){
203205
++numws;
@@ -207,11 +209,11 @@
207209
}
208210
}
209211
k -= numws;
210212
}else{
211213
for(h=0, x=s; x<k; x++){
212
- if( z[x]==0 ){
214
+ if( z[x]=='\0' ){
213215
fossil_free(a);
214216
return 0;
215217
}
216218
h += z[x];
217219
h *= 0x9e3779b1;
@@ -222,11 +224,11 @@
222224
h2 = h % nLine;
223225
a[i].iNext = a[h2].iHash;
224226
a[h2].iHash = i+1;
225227
z += nn+1; n -= nn+1;
226228
i++;
227
- }while( zNL[0] && zNL[1] );
229
+ }while( zNL[0]!='\0' && zNL[1]!='\0' );
228230
assert( i==nLine );
229231
230232
/* Return results */
231233
*pnLine = nLine;
232234
return a;
233235
--- src/diff.c
+++ src/diff.c
@@ -119,20 +119,22 @@
119 };
120
121 /*
122 ** Count the number of lines in the input string. Include the last line
123 ** in the count even if it lacks the \n terminator. If an empty string
124 ** is specified, the number of lines is zero.
 
 
125 */
126 static int count_lines(
127 const char *z,
128 int n
129 ){
130 int nLine;
131 const char *zNL, *z2;
132 for(nLine=0, z2=z; (zNL = fossil_strchr(z2,-1,'\n'))!=0; z2=zNL+1, nLine++){}
133 if( z2[0]!=0 ) nLine++;
134 return nLine;
135 }
136
137 /*
138 ** Return an array of DLine objects containing a pointer to the
@@ -159,11 +161,11 @@
159 unsigned int h, h2;
160 DLine *a;
161 const char *zNL;
162
163 nLine = count_lines(z, n);
164 assert( nLine>0 || z[0]==0 );
165 a = fossil_malloc( sizeof(a[0])*nLine );
166 memset(a, 0, sizeof(a[0])*nLine);
167 if( nLine==0 ){
168 if( fossil_strchr(z,n,'\0')!=0 ){
169 fossil_free(a);
@@ -193,11 +195,11 @@
193 }
194 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
195 int numws = 0;
196 while( s<k && fossil_isspace(z[s]) ){ s++; }
197 for(h=0, x=s; x<k; x++){
198 if( z[x]==0 ){
199 fossil_free(a);
200 return 0;
201 }
202 if( fossil_isspace(z[x]) ){
203 ++numws;
@@ -207,11 +209,11 @@
207 }
208 }
209 k -= numws;
210 }else{
211 for(h=0, x=s; x<k; x++){
212 if( z[x]==0 ){
213 fossil_free(a);
214 return 0;
215 }
216 h += z[x];
217 h *= 0x9e3779b1;
@@ -222,11 +224,11 @@
222 h2 = h % nLine;
223 a[i].iNext = a[h2].iHash;
224 a[h2].iHash = i+1;
225 z += nn+1; n -= nn+1;
226 i++;
227 }while( zNL[0] && zNL[1] );
228 assert( i==nLine );
229
230 /* Return results */
231 *pnLine = nLine;
232 return a;
233
--- src/diff.c
+++ src/diff.c
@@ -119,20 +119,22 @@
119 };
120
121 /*
122 ** Count the number of lines in the input string. Include the last line
123 ** in the count even if it lacks the \n terminator. If an empty string
124 ** is specified, the number of lines is zero. For the purposes of this
125 ** function, a string is considered empty if it contains no characters
126 ** -OR- it contains only NUL characters.
127 */
128 static int count_lines(
129 const char *z,
130 int n
131 ){
132 int nLine;
133 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;
137 }
138
139 /*
140 ** Return an array of DLine objects containing a pointer to the
@@ -159,11 +161,11 @@
161 unsigned int h, h2;
162 DLine *a;
163 const char *zNL;
164
165 nLine = count_lines(z, n);
166 assert( nLine>0 || z[0]=='\0' );
167 a = fossil_malloc( sizeof(a[0])*nLine );
168 memset(a, 0, sizeof(a[0])*nLine);
169 if( nLine==0 ){
170 if( fossil_strchr(z,n,'\0')!=0 ){
171 fossil_free(a);
@@ -193,11 +195,11 @@
195 }
196 if( (diffFlags & DIFF_IGNORE_ALLWS)==DIFF_IGNORE_ALLWS ){
197 int numws = 0;
198 while( s<k && fossil_isspace(z[s]) ){ s++; }
199 for(h=0, x=s; x<k; x++){
200 if( z[x]=='\0' ){
201 fossil_free(a);
202 return 0;
203 }
204 if( fossil_isspace(z[x]) ){
205 ++numws;
@@ -207,11 +209,11 @@
209 }
210 }
211 k -= numws;
212 }else{
213 for(h=0, x=s; x<k; x++){
214 if( z[x]=='\0' ){
215 fossil_free(a);
216 return 0;
217 }
218 h += z[x];
219 h *= 0x9e3779b1;
@@ -222,11 +224,11 @@
224 h2 = h % nLine;
225 a[i].iNext = a[h2].iHash;
226 a[h2].iHash = i+1;
227 z += nn+1; n -= nn+1;
228 i++;
229 }while( zNL[0]!='\0' && zNL[1]!='\0' );
230 assert( i==nLine );
231
232 /* Return results */
233 *pnLine = nLine;
234 return a;
235

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button