From d95e7debf8056a7c0744dca5946b49f611d0fa82 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 3 Feb 2009 00:43:13 +0000 Subject: [PATCH] Fixed off-by-one error in LexGetToken() git-svn-id: http://picoc.googlecode.com/svn/trunk@59 21eae674-98b7-11dd-bd71-f92a316d2d60 --- lex.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lex.c b/lex.c index cc34213..ae89f2b 100644 --- a/lex.c +++ b/lex.c @@ -302,6 +302,7 @@ void *LexTokenise(struct LexState *Lexer) do { /* store the token at the end of the stack area */ Token = LexScanGetToken(Lexer, &GotValue); + printf("Token: %02x\n", Token); *(char *)TokenSpace = Token; TokenSpace++; MemUsed++; @@ -326,7 +327,14 @@ void *LexTokenise(struct LexState *Lexer) LexFail(Lexer, "out of memory while lexing"); HeapMem = HeapAlloc(MemUsed); - memcpy(HeapMem, HeapStackGetFreeSpace(&MemAvailable), MemUsed); + memcpy(HeapMem, HeapStackGetFreeSpace(&MemAvailable), MemUsed); + { + int Count; + for (Count = 0; Count < MemUsed; Count++) + printf("%02x ", *(unsigned char *)(HeapMem+Count)); + printf("\n"); + } + return HeapMem; } @@ -377,7 +385,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I default: break; } - memcpy(LexValue.Val, Parser->Pos, ValueSize); + memcpy(LexValue.Val, Parser->Pos+1, ValueSize); LexValue.ValOnHeap = FALSE; LexValue.ValOnStack = FALSE; *Value = &LexValue; @@ -392,6 +400,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I Parser->Pos++; } + printf("Got token=%02x inc=%d\n", Token, IncPos); return Token; }