Skip to contentSkip to conversation

TCG: fix negative frame offset calculations

PATCH In review Blue Swirl 1 participant 1 message May 28, 2011

lore
Share & tools
lore

Blue Swirl

author
#0 lore raw

PATCH 2/18 TCG: fix negative frame offset calculations

size_t is unsigned, so the frame offset calculations can be incorrect for negative offsets.

---
 tcg/tcg.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
tcg/tcg.c +0 -1
index fad92f9..b31d80d 100644
@@ -1440,13 +1440,17 @@ static void temp_allocate_frame(TCGContext *s, int temp)
 {
     TCGTemp *ts;
     ts = &s->temps[temp];
-    s->current_frame_offset = (s->current_frame_offset +

sizeof(tcg_target_long) - 1) & ~(sizeof(tcg_target_long) - 1);
- if (s->current_frame_offset + sizeof(tcg_target_long) > s->frame_end)
+ s->current_frame_offset = (s->current_frame_offset +
+ (tcg_target_long)sizeof(tcg_target_long) - 1) &
+ ~(sizeof(tcg_target_long) - 1);
+ if (s->current_frame_offset + (tcg_target_long)sizeof(tcg_target_long) >

+        s->frame_end) {
         tcg_abort();
+    }
     ts->mem_offset = s->current_frame_offset;
     ts->mem_reg = s->frame_reg;
     ts->mem_allocated = 1;

- s->current_frame_offset += sizeof(tcg_target_long);
+ s->current_frame_offset += (tcg_target_long)sizeof(tcg_target_long);
}

/* free register 'reg' by spilling the corresponding temporary if necessary */

Signature · 1 line
1.6.2.4