Fossil SCM
More simplification in UTF-16 bom detection
Commit
1e70f211f9b37df4a8d9948b50f0585ca2ba7732
Parent
a98467b661faa7f…
1 file changed
+7
-12
+7
-12
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -370,29 +370,24 @@ | ||
| 370 | 370 | int starts_with_utf16_bom( |
| 371 | 371 | const Blob *pContent, /* IN: Blob content to perform BOM detection on. */ |
| 372 | 372 | int *pnByte, /* OUT: The number of bytes used for the BOM. */ |
| 373 | 373 | int *pbReverse /* OUT: Non-zero for BOM in reverse byte-order. */ |
| 374 | 374 | ){ |
| 375 | - const char *z = blob_buffer(pContent); | |
| 376 | - int bomSize = 2; | |
| 375 | + const unsigned short *z = (unsigned short *)blob_buffer(pContent); | |
| 376 | + const int bomSize = 2; | |
| 377 | 377 | static const unsigned short bom = 0xfeff; |
| 378 | 378 | static const unsigned short bom_reversed = 0xfffe; |
| 379 | - static const unsigned short null = 0; | |
| 380 | - int size; | |
| 379 | + int size = blob_size(pContent); | |
| 381 | 380 | |
| 382 | 381 | if( pnByte ) *pnByte = bomSize; |
| 383 | 382 | if( pbReverse ) *pbReverse = -1; /* Unknown. */ |
| 384 | - size = blob_size(pContent); | |
| 385 | - if( (size<bomSize) || (size%2) ) return 0; | |
| 386 | - if( memcmp(z, &bom_reversed, bomSize)==0 ){ | |
| 383 | + if( (size<bomSize) || (size%2) | |
| 384 | + || (size>=(2*bomSize) && z[1]==0) ) return 0; | |
| 385 | + if( z[0] == bom_reversed ){ | |
| 387 | 386 | if( pbReverse ) *pbReverse = 1; |
| 388 | - if( size<(2*bomSize) ) return 1; | |
| 389 | - if( memcmp(z+bomSize, &null, bomSize)!=0 ) return 1; | |
| 390 | - }else if( memcmp(z, &bom, bomSize)==0 ){ | |
| 387 | + }else if( z[0] == bom ){ | |
| 391 | 388 | if( pbReverse ) *pbReverse = 0; |
| 392 | - if( size<(2*bomSize) ) return 1; | |
| 393 | - if( memcmp(z+bomSize, &null, bomSize)!=0 ) return 1; | |
| 394 | 389 | } |
| 395 | 390 | return 0; |
| 396 | 391 | } |
| 397 | 392 | |
| 398 | 393 | /* |
| 399 | 394 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -370,29 +370,24 @@ | |
| 370 | int starts_with_utf16_bom( |
| 371 | const Blob *pContent, /* IN: Blob content to perform BOM detection on. */ |
| 372 | int *pnByte, /* OUT: The number of bytes used for the BOM. */ |
| 373 | int *pbReverse /* OUT: Non-zero for BOM in reverse byte-order. */ |
| 374 | ){ |
| 375 | const char *z = blob_buffer(pContent); |
| 376 | int bomSize = 2; |
| 377 | static const unsigned short bom = 0xfeff; |
| 378 | static const unsigned short bom_reversed = 0xfffe; |
| 379 | static const unsigned short null = 0; |
| 380 | int size; |
| 381 | |
| 382 | if( pnByte ) *pnByte = bomSize; |
| 383 | if( pbReverse ) *pbReverse = -1; /* Unknown. */ |
| 384 | size = blob_size(pContent); |
| 385 | if( (size<bomSize) || (size%2) ) return 0; |
| 386 | if( memcmp(z, &bom_reversed, bomSize)==0 ){ |
| 387 | if( pbReverse ) *pbReverse = 1; |
| 388 | if( size<(2*bomSize) ) return 1; |
| 389 | if( memcmp(z+bomSize, &null, bomSize)!=0 ) return 1; |
| 390 | }else if( memcmp(z, &bom, bomSize)==0 ){ |
| 391 | if( pbReverse ) *pbReverse = 0; |
| 392 | if( size<(2*bomSize) ) return 1; |
| 393 | if( memcmp(z+bomSize, &null, bomSize)!=0 ) return 1; |
| 394 | } |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -370,29 +370,24 @@ | |
| 370 | int starts_with_utf16_bom( |
| 371 | const Blob *pContent, /* IN: Blob content to perform BOM detection on. */ |
| 372 | int *pnByte, /* OUT: The number of bytes used for the BOM. */ |
| 373 | int *pbReverse /* OUT: Non-zero for BOM in reverse byte-order. */ |
| 374 | ){ |
| 375 | const unsigned short *z = (unsigned short *)blob_buffer(pContent); |
| 376 | const int bomSize = 2; |
| 377 | static const unsigned short bom = 0xfeff; |
| 378 | static const unsigned short bom_reversed = 0xfffe; |
| 379 | int size = blob_size(pContent); |
| 380 | |
| 381 | if( pnByte ) *pnByte = bomSize; |
| 382 | if( pbReverse ) *pbReverse = -1; /* Unknown. */ |
| 383 | if( (size<bomSize) || (size%2) |
| 384 | || (size>=(2*bomSize) && z[1]==0) ) return 0; |
| 385 | if( z[0] == bom_reversed ){ |
| 386 | if( pbReverse ) *pbReverse = 1; |
| 387 | }else if( z[0] == bom ){ |
| 388 | if( pbReverse ) *pbReverse = 0; |
| 389 | } |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 |