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:
authorAndrea Weikert <elubie@gmx.net>2007-03-19 22:34:04 +0300
committerAndrea Weikert <elubie@gmx.net>2007-03-19 22:34:04 +0300
commit7f2d1f651ca77e472a7b66b8c0eb8dbffe94ff34 (patch)
tree52592236942e5b65ba2a945e644737d262031919 /source/blender/blenlib
parent261120236b1c07d6c17d210f9012fb85bafe5497 (diff)
==== blenlib ====
- added replacement BLI_snprintf for snprintf to avoid MSVC specific #defines for snprintf. - BLI_snprintf also ensures trailing zero, so helps preventing buffer overflows
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_blenlib.h7
-rw-r--r--source/blender/blenlib/intern/util.c25
2 files changed, 32 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h
index 7b60aa178a7..464b851413f 100644
--- a/source/blender/blenlib/BLI_blenlib.h
+++ b/source/blender/blenlib/BLI_blenlib.h
@@ -69,6 +69,8 @@
because fillfacebase and fillvertbase are used outside */
#include "DNA_listBase.h"
+#include <stdlib.h>
+
extern ListBase fillfacebase;
extern ListBase fillvertbase;
/**
@@ -196,6 +198,11 @@ char* BLI_strdupn(char *str, int len);
*/
char* BLI_strncpy(char *dst, const char *src, int maxncpy);
+ /*
+ * Replacement for snprintf
+ */
+int BLI_snprintf(char *buffer, size_t count, const char *format, ...);
+
/**
* Compare two strings
*
diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c
index e4fc9cc92f9..2aa1b852ed3 100644
--- a/source/blender/blenlib/intern/util.c
+++ b/source/blender/blenlib/intern/util.c
@@ -40,6 +40,7 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
+#include <stdarg.h>
#include "MEM_guardedalloc.h"
@@ -65,6 +66,12 @@
#ifdef WIN32
#include "BLI_winstuff.h"
+
+/* for duplicate_defgroup */
+#if !(defined vsnprintf)
+#define vsnprintf _vsnprintf
+#endif
+
#endif
@@ -640,6 +647,24 @@ char *BLI_strncpy(char *dst, const char *src, int maxncpy) {
return dst;
}
+int BLI_snprintf(char *buffer, size_t count, const char *format, ...)
+{
+ int n;
+ va_list arg;
+
+ va_start(arg, format);
+ n = vsnprintf(buffer, count, format, arg);
+
+ if (n != -1 && n < count) {
+ buffer[n] = '\0';
+ } else {
+ buffer[count-1] = '\0';
+ }
+
+ va_end(arg);
+ return n;
+}
+
int BLI_streq(char *a, char *b) {
return (strcmp(a, b)==0);
}