Fossil SCM
Fix UTF-16 line length determination: j is counted in characters, not bytes.
Commit
44c6be2ab6d047152531f5f0681c2ea413c9fe5a
Parent
58702daa558730c…
1 file changed
+4
-4
+4
-4
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -209,33 +209,33 @@ | ||
| 209 | 209 | c = *z; |
| 210 | 210 | if( isBinary[c] ) return 0; /* non-text byte in a file -> binary */ |
| 211 | 211 | if ( (n&1)==0 ){ /* UTF-16 must have an even blob length */ |
| 212 | 212 | if ( (c==0xff) && (z[1]==0xfe) ){ /* UTF-16 LE BOM */ |
| 213 | 213 | result = -2; |
| 214 | - j = LENGTH_MASK*2/3; | |
| 214 | + j = LENGTH_MASK/3; | |
| 215 | 215 | while( (n-=2)>0 ){ |
| 216 | 216 | c = *(z+=2); |
| 217 | 217 | if( z[1]==0 ){ /* High-byte must be 0 for further checks */ |
| 218 | 218 | if( isBinary[c] ) return 0; /* non-text char in a file -> binary */ |
| 219 | 219 | if( c=='\n' ){ |
| 220 | - j = LENGTH_MASK; | |
| 220 | + j = LENGTH_MASK/3; | |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | if( --j==0 ){ |
| 224 | 224 | return 0; /* Very long line -> binary */ |
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | return result; |
| 228 | 228 | } else if ( (c==0xfe) && (z[1]==0xff) ){ /* UTF-16 BE BOM */ |
| 229 | 229 | result = -2; |
| 230 | - ++z; j = LENGTH_MASK*2/3; | |
| 230 | + ++z; j = LENGTH_MASK/3; | |
| 231 | 231 | while( (n-=2)>0 ){ |
| 232 | 232 | c = *(z+=2); |
| 233 | 233 | if ( z[-1]==0 ){ /* High-byte must be 0 for further checks */ |
| 234 | 234 | if( isBinary[c] ) return 0; /* non-text char in a file -> binary */ |
| 235 | 235 | if( c=='\n' ){ |
| 236 | - j = LENGTH_MASK; | |
| 236 | + j = LENGTH_MASK/3; | |
| 237 | 237 | } |
| 238 | 238 | } |
| 239 | 239 | if( --j==0 ){ |
| 240 | 240 | return 0; /* Very long line -> binary */ |
| 241 | 241 | } |
| 242 | 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*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 |