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>2012-10-31 08:28:49 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-10-31 08:28:49 +0400
commitfd2907a0b656f06c90243a5956df44d47d4bddd6 (patch)
tree1795fc58c0aea430d1d0ffdb7c9a7db6cf05fb5a /source/blender/blenlib
parentac86beb0e569075e2bd6e2da914bda2831b06c18 (diff)
add assert if zero is passed to string copy functions, would copy into first byte anyway.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_string.h2
-rw-r--r--source/blender/blenlib/intern/string.c13
-rw-r--r--source/blender/blenlib/intern/string_utf8.c6
3 files changed, 15 insertions, 6 deletions
diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h
index ba906e1221c..70c89773f02 100644
--- a/source/blender/blenlib/BLI_string.h
+++ b/source/blender/blenlib/BLI_string.h
@@ -162,7 +162,7 @@ __attribute__((nonnull))
#endif
;
-size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxlen)
+size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
#ifdef __GNUC__
__attribute__((nonnull))
#endif
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 73d88ddd259..ff589764287 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -41,6 +41,8 @@
#include "BLI_dynstr.h"
#include "BLI_string.h"
+#include "BLI_utildefines.h"
+
char *BLI_strdupn(const char *str, const size_t len)
{
char *n = MEM_mallocN(len + 1, "strdup");
@@ -71,6 +73,7 @@ char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy)
{
size_t srclen = strlen(src);
size_t cpylen = (srclen > (maxncpy - 1)) ? (maxncpy - 1) : srclen;
+ BLI_assert(maxncpy != 0);
memcpy(dst, src, cpylen);
dst[cpylen] = '\0';
@@ -130,10 +133,13 @@ char *BLI_sprintfN(const char *format, ...)
* TODO: support more fancy string escaping. current code is primitive
* this basically is an ascii version of PyUnicode_EncodeUnicodeEscape()
* which is a useful reference. */
-size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
+size_t BLI_strescape(char *dst, const char *src, const size_t maxncpy)
{
size_t len = 0;
- while (len < maxlen) {
+
+ BLI_assert(maxncpy != 0);
+
+ while (len < maxncpy) {
switch (*src) {
case '\0':
goto escape_finish;
@@ -144,7 +150,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen)
case '\t':
case '\n':
case '\r':
- if (len + 1 < maxlen) {
+ if (len + 1 < maxncpy) {
*dst++ = '\\';
len++;
}
@@ -439,4 +445,3 @@ void BLI_ascii_strtoupper(char *str, const size_t len)
if (str[i] >= 'a' && str[i] <= 'z')
str[i] -= 'a' - 'A';
}
-
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index a8960f1abbb..59f8e7458e1 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -33,8 +33,12 @@
#include <string.h>
#include <wchar.h>
#include <wctype.h>
+#include <stdio.h>
+#include <stdlib.h>
-#include "BLI_string_utf8.h"
+#include "BLI_utildefines.h"
+
+#include "BLI_string_utf8.h" /* own include */
/* from libswish3, originally called u8_isvalid(),
* modified to return the index of the bad character (byte index not utf).