Skip to content

Commit a995328

Browse files
committed
Minor update binary file detection, issue #953.
1 parent b591eae commit a995328

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/EditEncoding.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1045,12 +1045,13 @@ bool MaybeBinaryFile(const uint8_t *ptr, DWORD length) noexcept {
10451045
length = min<DWORD>(length, 1024);
10461046
const uint8_t * const end = ptr + length;
10471047
UINT count = 0;
1048+
UINT mask = 0; // find two different C0 control characters
10481049
while (ptr < end) {
1049-
uint8_t ch = *ptr++;
1050+
const uint8_t ch = *ptr++;
10501051
if (IsC0ControlChar(ch)) {
10511052
++count;
1052-
ch = *ptr++;
1053-
if ((count >= 8) || IsC0ControlChar(ch)) {
1053+
mask |= 1U << ch;
1054+
if (((mask & (mask - 1)) != 0) && ((count >= 8) || IsC0ControlChar(*ptr))) {
10541055
return true;
10551056
}
10561057
}

0 commit comments

Comments
 (0)