Skip to content

Commit

Permalink
Fix tautological-constant-out-of-range-compare with Clang on macOS
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 373424469
Change-Id: Ia6e89e1872f98adc5f1c1b36a601df8d351080ab
  • Loading branch information
cblichmann authored and copybara-github committed May 12, 2021
1 parent 933e158 commit 6a21a82
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
4 changes: 1 addition & 3 deletions ida/flow_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ void AnalyzeFlowIda(EntryPoints* entry_points, const ModuleMap& modules,
if (mark_x86_nops) {
// FLAG_NOP is only important when reconstructing functions, thus we can
// set if after AnalyzeFlow().
const auto& new_instruction_bytes = new_instruction.GetBytes();
new_instruction.SetFlag(FLAG_NOP, IsNopX86(new_instruction_bytes.data(),
new_instruction_bytes.size()));
new_instruction.SetFlag(FLAG_NOP, IsNopX86(new_instruction.GetBytes()));
}

instructions->push_back(new_instruction);
Expand Down
21 changes: 14 additions & 7 deletions x86_nop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

#include "third_party/zynamics/binexport/x86_nop.h"

bool IsNopX86(const char* m, size_t size) {
#include <cstdint>

bool IsNopX86(absl::string_view bytes) {
auto* m = reinterpret_cast<const uint8_t*>(bytes.data());
size_t size = bytes.size();

// Consume up to six prefix bytes:
for (int i = 6; i > 0 && size > 0 && m[0] == 0x66; --i, --size, ++m) {
}
Expand Down Expand Up @@ -52,7 +57,8 @@ bool IsNopX86(const char* m, size_t size) {
if (m[1] == 0x74) {
if (m[2] == 0x00) {
return true; // 8d 74 00 lea esi, esi
} else if (m[2] == 0x26) {
}
if (m[2] == 0x26) {
if (size >= 4 && m[3] == 0x00) {
return true; // 8d 74 26 00 lea esi, [esi + eiz * 1 + 0]
}
Expand All @@ -64,8 +70,9 @@ bool IsNopX86(const char* m, size_t size) {
if (m[1] == 0xb4) {
if (m[2] == 0x00 && m[3] == 0x00) {
return true; // 8d b4 00 00 lea
} else if (size >= 7 && m[2] == 0x26 && m[3] == 0x00 &&
m[4] == 0x00 && m[5] == 0x00 && m[6] == 0x00) {
}
if (size >= 7 && m[2] == 0x26 && m[3] == 0x00 && m[4] == 0x00 &&
m[5] == 0x00 && m[6] == 0x00) {
return true; // 8d b4 26 00 00 00 00 lea
}
} else if (m[1] == 0xbd && m[2] == 0x00 && m[3] == 0x00) {
Expand All @@ -75,8 +82,9 @@ bool IsNopX86(const char* m, size_t size) {
if (m[1] == 0xb6 && m[2] == 0x00 && m[3] == 0x00 && m[4] == 0x00 &&
m[5] == 0x00) {
return true; // 8d b6 00 00 00 00 lea
} else if (m[1] == 0xbf && m[2] == 0x00 && m[3] == 0x00 &&
m[4] == 0x00 && m[5] == 0x00) {
}
if (m[1] == 0xbf && m[2] == 0x00 && m[3] == 0x00 && m[4] == 0x00 &&
m[5] == 0x00) {
return true; // 8d bf 00 00 00 00 lea
}
if (size >= 7 && m[1] == 0xbc && m[2] == 0x27 && m[3] == 0x00 &&
Expand All @@ -95,4 +103,3 @@ bool IsNopX86(const char* m, size_t size) {
}
return false;
}

10 changes: 6 additions & 4 deletions x86_nop.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

#include <cstddef>

// Returns true if the instruction starting at "memory" (which contains at least
// "size" bytes) is a NOP instruction. NOPs have been taken from the GNU
// assembler tc-i386.c i386_align_code().
#include "third_party/absl/strings/string_view.h"

// Returns true if the instruction starting at the first byte in "bytes" is a
// NOP instruction. NOPs have been taken from the GNU assembler
// i386_align_code() (in tc-i386.c).
// For details, see b/24084521#comment7
bool IsNopX86(const char* m, size_t size);
bool IsNopX86(absl::string_view bytes);

#endif // X86_NOP_H_

0 comments on commit 6a21a82

Please sign in to comment.