Fossil SCM

Fix UTF-16 line length determination: j is counted in characters, not bytes.

jan.nijtmans 2012-10-31 09:15 UTC improve_looks_like_binary
Commit 44c6be2ab6d047152531f5f0681c2ea413c9fe5a
1 file changed +4 -4
+4 -4
--- src/diff.c
+++ src/diff.c
@@ -209,33 +209,33 @@
209209
c = *z;
210210
if( isBinary[c] ) return 0; /* non-text byte in a file -> binary */
211211
if ( (n&1)==0 ){ /* UTF-16 must have an even blob length */
212212
if ( (c==0xff) && (z[1]==0xfe) ){ /* UTF-16 LE BOM */
213213
result = -2;
214
- j = LENGTH_MASK*2/3;
214
+ j = LENGTH_MASK/3;
215215
while( (n-=2)>0 ){
216216
c = *(z+=2);
217217
if( z[1]==0 ){ /* High-byte must be 0 for further checks */
218218
if( isBinary[c] ) return 0; /* non-text char in a file -> binary */
219219
if( c=='\n' ){
220
- j = LENGTH_MASK;
220
+ j = LENGTH_MASK/3;
221221
}
222222
}
223223
if( --j==0 ){
224224
return 0; /* Very long line -> binary */
225225
}
226226
}
227227
return result;
228228
} else if ( (c==0xfe) && (z[1]==0xff) ){ /* UTF-16 BE BOM */
229229
result = -2;
230
- ++z; j = LENGTH_MASK*2/3;
230
+ ++z; j = LENGTH_MASK/3;
231231
while( (n-=2)>0 ){
232232
c = *(z+=2);
233233
if ( z[-1]==0 ){ /* High-byte must be 0 for further checks */
234234
if( isBinary[c] ) return 0; /* non-text char in a file -> binary */
235235
if( c=='\n' ){
236
- j = LENGTH_MASK;
236
+ j = LENGTH_MASK/3;
237237
}
238238
}
239239
if( --j==0 ){
240240
return 0; /* Very long line -> binary */
241241
}
242242
--- src/diff.c
+++ src/diff.c
@@ -209,33 +209,33 @@
209 c = *z;
210 if( isBinary[c] ) return 0; /* non-text byte in a file -> binary */
211 if ( (n&1)==0 ){ /* UTF-16 must have an even blob length */
212 if ( (c==0xff) && (z[1]==0xfe) ){ /* UTF-16 LE BOM */
213 result = -2;
214 j = LENGTH_MASK*2/3;
215 while( (n-=2)>0 ){
216 c = *(z+=2);
217 if( z[1]==0 ){ /* High-byte must be 0 for further checks */
218 if( isBinary[c] ) return 0; /* non-text char in a file -> binary */
219 if( c=='\n' ){
220 j = LENGTH_MASK;
221 }
222 }
223 if( --j==0 ){
224 return 0; /* Very long line -> binary */
225 }
226 }
227 return result;
228 } else if ( (c==0xfe) && (z[1]==0xff) ){ /* UTF-16 BE BOM */
229 result = -2;
230 ++z; j = LENGTH_MASK*2/3;
231 while( (n-=2)>0 ){
232 c = *(z+=2);
233 if ( z[-1]==0 ){ /* High-byte must be 0 for further checks */
234 if( isBinary[c] ) return 0; /* non-text char in a file -> binary */
235 if( c=='\n' ){
236 j = LENGTH_MASK;
237 }
238 }
239 if( --j==0 ){
240 return 0; /* Very long line -> binary */
241 }
242
--- src/diff.c
+++ src/diff.c
@@ -209,33 +209,33 @@
209 c = *z;
210 if( isBinary[c] ) return 0; /* non-text byte in a file -> binary */
211 if ( (n&1)==0 ){ /* UTF-16 must have an even blob length */
212 if ( (c==0xff) && (z[1]==0xfe) ){ /* UTF-16 LE BOM */
213 result = -2;
214 j = LENGTH_MASK/3;
215 while( (n-=2)>0 ){
216 c = *(z+=2);
217 if( z[1]==0 ){ /* High-byte must be 0 for further checks */
218 if( isBinary[c] ) return 0; /* non-text char in a file -> binary */
219 if( c=='\n' ){
220 j = LENGTH_MASK/3;
221 }
222 }
223 if( --j==0 ){
224 return 0; /* Very long line -> binary */
225 }
226 }
227 return result;
228 } else if ( (c==0xfe) && (z[1]==0xff) ){ /* UTF-16 BE BOM */
229 result = -2;
230 ++z; j = LENGTH_MASK/3;
231 while( (n-=2)>0 ){
232 c = *(z+=2);
233 if ( z[-1]==0 ){ /* High-byte must be 0 for further checks */
234 if( isBinary[c] ) return 0; /* non-text char in a file -> binary */
235 if( c=='\n' ){
236 j = LENGTH_MASK/3;
237 }
238 }
239 if( --j==0 ){
240 return 0; /* Very long line -> binary */
241 }
242

Keyboard Shortcuts

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