==== 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
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -217,14 +217,14 @@ void duplicate_defgroup ( Object *ob )
|
||||
if (!dg)
|
||||
return;
|
||||
|
||||
snprintf (name, 32, "%s_copy", dg->name);
|
||||
BLI_snprintf (name, 32, "%s_copy", dg->name);
|
||||
while (get_named_vertexgroup (ob, name)) {
|
||||
if ((strlen (name) + 6) > 32) {
|
||||
error ("Error: the name for the new group is > 32 characters");
|
||||
return;
|
||||
}
|
||||
strcpy (s, name);
|
||||
snprintf (name, 32, "%s_copy", s);
|
||||
BLI_snprintf (name, 32, "%s_copy", s);
|
||||
}
|
||||
|
||||
cdg = copy_defgroup (dg);
|
||||
|
||||
Reference in New Issue
Block a user