Mercurial > hg > nnchat
changeset 79:e36df57c5b0f
Use th_strdup() again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 24 Dec 2008 16:03:53 +0200 |
parents | 745f670068dc |
children | 335b5a74c22e |
files | libnnchat.c nnchat.c th_string.c th_string.h |
diffstat | 4 files changed, 23 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libnnchat.c Thu Dec 18 14:34:44 2008 +0200 +++ b/libnnchat.c Wed Dec 24 16:03:53 2008 +0200 @@ -392,12 +392,12 @@ void addRingBuf(ringbuf_t *buf, const char *str) { if (buf->n < buf->size) { - buf->data[buf->n] = strdup(str); + buf->data[buf->n] = th_strdup(str); buf->n++; } else { th_free(buf->data[0]); memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1); - buf->data[buf->size - 1] = strdup(str); + buf->data[buf->size - 1] = th_strdup(str); } }
--- a/nnchat.c Thu Dec 18 14:34:44 2008 +0200 +++ b/nnchat.c Wed Dec 24 16:03:53 2008 +0200 @@ -534,7 +534,7 @@ return 0; } else if (!strncmp(buf, "/to ", 4)) { th_free(setTarget); - setTarget = strdup(buf + 4); + setTarget = th_strdup(buf + 4); printMsg("Set prv target to '%s'\n", setTarget); return 0; } else if (!strncmp(buf, "/who", 4)) {
--- a/th_string.c Thu Dec 18 14:34:44 2008 +0200 +++ b/th_string.c Wed Dec 24 16:03:53 2008 +0200 @@ -13,6 +13,23 @@ #define LPREV (pNode->pPrev) #define LNEXT (pNode->pNext) + +/* strdup with a NULL check + */ +char *th_strdup(const char *s) +{ + char *res; + if (s == NULL) + return NULL; + + if ((res = th_malloc(strlen(s) + 1)) == NULL) + return NULL; + + strcpy(res, s); + return res; +} + + /* Allocate memory for a string with given length */ char *th_stralloc(const size_t l)
--- a/th_string.h Thu Dec 18 14:34:44 2008 +0200 +++ b/th_string.h Wed Dec 24 16:03:53 2008 +0200 @@ -48,8 +48,9 @@ int th_strncasecmp(char *, char *, size_t); void th_strip_ctrlchars(char *); -int th_pstrcpy(char **, char *); -int th_pstrcat(char **, char *); +char *th_strdup(const char *); +int th_pstrcpy(char **, char *); +int th_pstrcat(char **, char *); char *th_findnext(char *, size_t *); char *th_findsep(char *, size_t *, char);