Mercurial > trustbridge
diff common/strhelp.h @ 60:6acb1dae6185
Use strn functions and improve error handling.
Even if we know the strings are NULL terminated we use
length terminated string functions after a first strlen
this makes it easier to assert that at one point we know
the string is terminated and afterwards use the length
of that.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 18 Mar 2014 11:28:02 +0000 |
parents | 3f6378647371 |
children | 80ab2168760f |
line wrap: on
line diff
--- a/common/strhelp.h Tue Mar 18 10:04:30 2014 +0000 +++ b/common/strhelp.h Tue Mar 18 11:28:02 2014 +0000 @@ -1,3 +1,5 @@ +#ifndef STRHELP_H +#define STRHELP_H /* @file Helper functions for c strings and memory management * * strhelp contains terminating memory allocation functions and @@ -7,7 +9,7 @@ void *xmalloc( size_t n ); void *xrealloc( void *a, size_t n ); void *xcalloc( size_t n, size_t m ); -char *xstrdup( const char *string ); +char *xstrndup( const char *string, const size_t len ); /** * strv_length: @@ -25,14 +27,17 @@ * * @param[inout] array pointer to the NULL terminated list of string pointers. * @param[in] string pointer to the string to append to the list. + * @param[in] len length of the string to append to the list * */ -void array_append_str(char ***pArray, const char *string); +void array_append_str(char ***pArray, const char *string, const size_t len); /* @brief append a string to another string. * * @param[inout] pDst pointer to the string to be extended. * @param[in] appendage pointer to the string to append. + * @param[in] len length of the string to append. * */ -void str_append_str(char **pDst, const char *appendage); +void str_append_str(char **pDst, const char *appendage, const size_t len); void strfreev (char **str_array); +#endif