diff options
| author | chalcy0n <jeroen@jeroennijhof.nl> | 2013-04-28 03:57:15 -0700 |
|---|---|---|
| committer | chalcy0n <jeroen@jeroennijhof.nl> | 2013-04-28 03:57:15 -0700 |
| commit | 10df9486a13dc38349e0e7e0fbe9df35f0750071 (patch) | |
| tree | ee3b25478b2ba06fe7850a5615d0a37ed419e7fd /libtac/lib/xalloc.c | |
| parent | 5f630f12babd86f1b3b3fc1bd40a0fe042826780 (diff) | |
| parent | bb9f348decdd37b4d126bff67ed1e913eb28c3cb (diff) | |
| download | pam_tacplus-10df9486a13dc38349e0e7e0fbe9df35f0750071.tar.gz pam_tacplus-10df9486a13dc38349e0e7e0fbe9df35f0750071.zip | |
Merge pull request #6 from walterdejong/master
cleanup stuff
Diffstat (limited to 'libtac/lib/xalloc.c')
| -rw-r--r-- | libtac/lib/xalloc.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/libtac/lib/xalloc.c b/libtac/lib/xalloc.c index ce34c44..3fddcfb 100644 --- a/libtac/lib/xalloc.c +++ b/libtac/lib/xalloc.c @@ -23,7 +23,7 @@ #include "xalloc.h" void *xcalloc(size_t nmemb, size_t size) { - register void *val = calloc(nmemb, size); + void *val = calloc(nmemb, size); if(val == 0) { TACSYSLOG((LOG_ERR, "%s: calloc(%u,%u) failed", __FUNCTION__,\ (unsigned) nmemb, (unsigned) size)) @@ -33,7 +33,7 @@ void *xcalloc(size_t nmemb, size_t size) { } void *xrealloc(void *ptr, size_t size) { - register void *val = realloc(ptr, size); + void *val = realloc(ptr, size); if(val == 0) { TACSYSLOG((LOG_ERR, "%s: realloc(%u) failed", __FUNCTION__, (unsigned) size)) exit(1); @@ -41,7 +41,7 @@ void *xrealloc(void *ptr, size_t size) { return val; } -char *xstrdup(char *s) { +char *xstrdup(const char *s) { char *p; if (s == NULL) return NULL; @@ -51,3 +51,28 @@ char *xstrdup(char *s) { } return p; } + + +/* + safe string copy that aborts when destination buffer is too small +*/ +char *xstrcpy(char *dst, const char *src, size_t dst_size) { + if (dst == NULL) { + TACSYSLOG((LOG_ERR, "xstrcpy(): dst == NULL")); + abort(); + } + if (src == NULL) { + TACSYSLOG((LOG_ERR, "xstrcpy(): src == NULL")); + abort(); + } + if (!dst_size) + return NULL; + + if (strlen(src) >= dst_size) { + TACSYSLOG((LOG_ERR, "xstrcpy(): argument too long, aborting")); + abort(); + } + + return strcpy(dst, src); +} + |
