Skip to content

Commit

Permalink
Add function attributes to functions in memory.h #811
Browse files Browse the repository at this point in the history
Add missing function attributes in memory.h. Fixes #806
  • Loading branch information
wesleywiser authored and justinmk committed Jun 10, 2014
1 parent 785b16d commit a321480
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/nvim/memory.c
Expand Up @@ -186,6 +186,7 @@ void *xrealloc(void *ptr, size_t size)
/// @param size
/// @return pointer to allocated space. Never NULL
void *xmallocz(size_t size)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
{
size_t total_size = size + 1;
void *ret;
Expand All @@ -210,6 +211,8 @@ void *xmallocz(size_t size)
/// @param data Pointer to the data that will be copied
/// @param len number of bytes that will be copied
void *xmemdupz(const void *data, size_t len)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
FUNC_ATTR_NONNULL_ALL
{
return memcpy(xmallocz(len), data, len);
}
Expand All @@ -231,6 +234,7 @@ void *xmemdupz(const void *data, size_t len)
/// @param dst
/// @param src
char *xstpcpy(char *restrict dst, const char *restrict src)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const size_t len = strlen(src);
return (char *)memcpy(dst, src, len + 1) + len;
Expand Down Expand Up @@ -258,6 +262,7 @@ char *xstpcpy(char *restrict dst, const char *restrict src)
/// @param src
/// @param maxlen
char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
const char *p = memchr(src, '\0', maxlen);
if (p) {
Expand Down Expand Up @@ -336,6 +341,8 @@ char *xstrndup(const char *str, size_t len)
/// @param len size of the chunk
/// @return a pointer
void *xmemdup(const void *data, size_t len)
FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(2) FUNC_ATTR_NONNULL_RET
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
return memcpy(xmalloc(len), data, len);
}
Expand Down

0 comments on commit a321480

Please sign in to comment.