From 7306924785988fdefcf2252749f42cb299b53d13 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 10 Mar 2009 21:59:18 +0000 Subject: [PATCH] Fixed a null-termination bug in StrRegister() git-svn-id: http://picoc.googlecode.com/svn/trunk@188 21eae674-98b7-11dd-bd71-f92a316d2d60 --- table.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/table.c b/table.c index 6bf5333..df7bffb 100644 --- a/table.c +++ b/table.c @@ -114,10 +114,14 @@ char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen) else { /* add it to the table - we economise by not allocating the whole structure here */ struct TableEntry *NewEntry = HeapAlloc(sizeof(struct TableEntry *) + IdentLen + 1); + printf("allocated 0x%lx:%d for '", (unsigned long)NewEntry, sizeof(struct TableEntry *) + IdentLen + 1); + fwrite(Ident, 1, IdentLen, stdout); + printf("'\n"); if (NewEntry == NULL) ProgramFail(NULL, "out of memory"); strncpy((char *)&NewEntry->p.Key[0], Ident, IdentLen); + NewEntry->p.Key[IdentLen] = '\0'; NewEntry->Next = Tbl->HashTable[AddAt]; Tbl->HashTable[AddAt] = NewEntry; return &NewEntry->p.Key[0];