summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralkondratenko@gmail.com <alkondratenko@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2013-05-07 19:22:45 +0000
committeralkondratenko@gmail.com <alkondratenko@gmail.com@6b5cf1ce-ec42-a296-1ba9-69fdba395a50>2013-05-07 19:22:45 +0000
commitc45bb7d6033952ea33bb181c1f96999317b535a1 (patch)
tree81ec01c867550e87cd5fc4e8f6598f790abefaf3
parent3567b1701aa55a6421aefa5f3de1ca5507cbdf79 (diff)
downloadgperftools-c45bb7d6033952ea33bb181c1f96999317b535a1.tar.gz
issue-511: fixed negative offset handling for conditional jumps
While doing and testing issue-511 I've found one subtle bug which is incorrect handling of short offsets. They are defined to be signed but previous code used unsigned char for them which caused negative offsets to look like larger positive offsets. Fix is trivial. git-svn-id: http://gperftools.googlecode.com/svn/trunk@215 6b5cf1ce-ec42-a296-1ba9-69fdba395a50
-rw-r--r--src/windows/preamble_patcher.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/windows/preamble_patcher.cc b/src/windows/preamble_patcher.cc
index 51a5af7..59624f0 100644
--- a/src/windows/preamble_patcher.cc
+++ b/src/windows/preamble_patcher.cc
@@ -594,7 +594,9 @@ SideStepError PreamblePatcher::PatchShortConditionalJump(
unsigned char* target,
unsigned int* target_bytes,
unsigned int target_size) {
- unsigned char* original_jump_dest = (source + 2) + source[1];
+ // note: rel8 offset is signed. Thus we need to ask for signed char
+ // to negative offsets right
+ unsigned char* original_jump_dest = (source + 2) + static_cast<signed char>(source[1]);
unsigned char* stub_jump_from = target + 6;
__int64 fixup_jump_offset = original_jump_dest - stub_jump_from;
if (fixup_jump_offset > INT_MAX || fixup_jump_offset < INT_MIN) {