From: mdw Date: Thu, 25 Jan 2001 21:14:49 +0000 (+0000) Subject: Always add a terminating null, and don't count it in the length. X-Git-Tag: 2.0.4~112 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/commitdiff_plain/ec6770ddae55110cf71b73e2bce70150a39a17c3?hp=f41204b39ae4de668eae0f4683e6c8590172f7f2 Always add a terminating null, and don't count it in the length. --- diff --git a/sym.c b/sym.c index c6d1e43..3aea8c7 100644 --- a/sym.c +++ b/sym.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: sym.c,v 1.12 2001/01/20 11:49:37 mdw Exp $ + * $Id: sym.c,v 1.13 2001/01/25 21:14:49 mdw Exp $ * * Symbol table management * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: sym.c,v $ + * Revision 1.13 2001/01/25 21:14:49 mdw + * Always add a terminating null, and don't count it in the length. + * * Revision 1.12 2001/01/20 11:49:37 mdw * Export tuning parameters from header file, for the benefit of other * hashtable implementations. Change the storage of symbol names: store @@ -175,7 +178,7 @@ void *sym_find(sym_table *t, const char *n, long l, size_t sz, unsigned *f) /* --- Find the correct bin --- */ - len = l < 0 ? strlen(n) + 1 : l; + len = l < 0 ? strlen(n) : l; CRC32(hash, 0, n, len); bin = HASH_BIN(&t->t, hash); @@ -212,11 +215,12 @@ void *sym_find(sym_table *t, const char *n, long l, size_t sz, unsigned *f) * The name is attached to the end of the symbol block. */ - q = x_alloc(t->t.a, sz + len); + q = x_alloc(t->t.a, sz + len + 1); q->b.next = *bin; q->b.hash = hash; q->name = (char *)q + sz; memcpy(q->name, n, len); + q->name[len] = 0; q->len = len; *bin = &q->b;