Fixed a null-termination bug in StrRegister()
git-svn-id: http://picoc.googlecode.com/svn/trunk@188 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
6a586cee75
commit
7306924785
4
table.c
4
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];
|
||||
|
|
Loading…
Reference in a new issue