Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-07-15 07:54:57 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-07-15 07:54:57 +0400
commit02f5b0fc08e979dab65a7bc1ee0383098ac99b2e (patch)
tree3ef72ad141a74612d3c77b031fff0dfc54f87f08 /source/blender/blenlib/intern/string.c
parenta91f51b67b48c0a78032ed569d5a163718ec5cce (diff)
debug option (off by default), for BLI_string to help find incorrect sizes being passed in (enable in source files only)
Diffstat (limited to 'source/blender/blenlib/intern/string.c')
-rw-r--r--source/blender/blenlib/intern/string.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 03bed428c07..24e14d04c68 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -47,6 +47,8 @@
# pragma GCC diagnostic error "-Wsign-conversion"
#endif
+// #define DEBUG_STRSIZE
+
/**
* Duplicates the first \a len bytes of cstring \a str
* into a newly mallocN'd string and returns it. \a str
@@ -111,6 +113,10 @@ char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t
size_t srclen = BLI_strnlen(src, maxncpy - 1);
BLI_assert(maxncpy != 0);
+#ifdef DEBUG_STRSIZE
+ memset(dst, 0xff, sizeof(*dst) * maxncpy);
+#endif
+
memcpy(dst, src, srclen);
dst[srclen] = '\0';
return dst;
@@ -134,6 +140,10 @@ size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, const
size_t srclen = BLI_strnlen(src, maxncpy - 1);
BLI_assert(maxncpy != 0);
+#ifdef DEBUG_STRSIZE
+ memset(dst, 0xff, sizeof(*dst) * maxncpy);
+#endif
+
memcpy(dst, src, srclen);
dst[srclen] = '\0';
return srclen;
@@ -149,21 +159,21 @@ size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src)
/**
* Portable replacement for #vsnprintf
*/
-size_t BLI_vsnprintf(char *__restrict buffer, size_t count, const char *__restrict format, va_list arg)
+size_t BLI_vsnprintf(char *__restrict buffer, size_t maxncpy, const char *__restrict format, va_list arg)
{
size_t n;
BLI_assert(buffer != NULL);
- BLI_assert(count > 0);
+ BLI_assert(maxncpy > 0);
BLI_assert(format != NULL);
- n = (size_t)vsnprintf(buffer, count, format, arg);
+ n = (size_t)vsnprintf(buffer, maxncpy, format, arg);
- if (n != -1 && n < count) {
+ if (n != -1 && n < maxncpy) {
buffer[n] = '\0';
}
else {
- buffer[count - 1] = '\0';
+ buffer[maxncpy - 1] = '\0';
}
return n;
@@ -172,13 +182,17 @@ size_t BLI_vsnprintf(char *__restrict buffer, size_t count, const char *__restri
/**
* Portable replacement for #snprintf
*/
-size_t BLI_snprintf(char *__restrict buffer, size_t count, const char *__restrict format, ...)
+size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format, ...)
{
size_t n;
va_list arg;
+#ifdef DEBUG_STRSIZE
+ memset(dst, 0xff, sizeof(*dst) * maxncpy);
+#endif
+
va_start(arg, format);
- n = BLI_vsnprintf(buffer, count, format, arg);
+ n = BLI_vsnprintf(dst, maxncpy, format, arg);
va_end(arg);
return n;