use size_t rather then int for passing lengths to string functions since this is what guarded-malloc uses as well as stdlib.h.

This commit is contained in:
Campbell Barton 2011-03-25 13:40:44 +00:00
parent 21e0eff897
commit 77a1a2f14e
2 changed files with 16 additions and 16 deletions

@ -58,7 +58,7 @@ char *BLI_strdup(const char *str);
* @param len The number of bytes to duplicate * @param len The number of bytes to duplicate
* @retval Returns the duplicated string * @retval Returns the duplicated string
*/ */
char *BLI_strdupn(const char *str, int len); char *BLI_strdupn(const char *str, const size_t len);
/** /**
* Appends the two strings, and returns new mallocN'ed string * Appends the two strings, and returns new mallocN'ed string
@ -78,7 +78,7 @@ char *BLI_strdupcat(const char *str1, const char *str2);
* the size of dst) * the size of dst)
* @retval Returns dst * @retval Returns dst
*/ */
char *BLI_strncpy(char *dst, const char *src, const int maxncpy); char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy);
/* Makes a copy of the text within the "" that appear after some text 'blahblah' /* Makes a copy of the text within the "" that appear after some text 'blahblah'
* i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples" * i.e. for string 'pose["apples"]' with prefix 'pose[', it should grab "apples"
@ -106,7 +106,7 @@ char *BLI_replacestr(char *str, const char *oldText, const char *newText);
/* /*
* Replacement for snprintf * Replacement for snprintf
*/ */
int BLI_snprintf(char *buffer, size_t count, const char *format, ...) size_t BLI_snprintf(char *buffer, size_t len, const char *format, ...)
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__ ((format (printf, 3, 4))) __attribute__ ((format (printf, 3, 4)))
#endif #endif
@ -138,7 +138,7 @@ int BLI_strcaseeq(const char *a, const char *b);
char *BLI_strcasestr(const char *s, const char *find); char *BLI_strcasestr(const char *s, const char *find);
int BLI_strcasecmp(const char *s1, const char *s2); int BLI_strcasecmp(const char *s1, const char *s2);
int BLI_strncasecmp(const char *s1, const char *s2, int n); int BLI_strncasecmp(const char *s1, const char *s2, size_t len);
int BLI_natstrcmp(const char *s1, const char *s2); int BLI_natstrcmp(const char *s1, const char *s2);
size_t BLI_strnlen(const char *str, size_t maxlen); size_t BLI_strnlen(const char *str, size_t maxlen);

@ -47,7 +47,7 @@
#include "BLI_dynstr.h" #include "BLI_dynstr.h"
#include "BLI_string.h" #include "BLI_string.h"
char *BLI_strdupn(const char *str, int len) { char *BLI_strdupn(const char *str, const size_t len) {
char *n= MEM_mallocN(len+1, "strdup"); char *n= MEM_mallocN(len+1, "strdup");
memcpy(n, str, len); memcpy(n, str, len);
n[len]= '\0'; n[len]= '\0';
@ -60,7 +60,7 @@ char *BLI_strdup(const char *str) {
char *BLI_strdupcat(const char *str1, const char *str2) char *BLI_strdupcat(const char *str1, const char *str2)
{ {
int len; size_t len;
char *n; char *n;
len= strlen(str1)+strlen(str2); len= strlen(str1)+strlen(str2);
@ -71,9 +71,9 @@ char *BLI_strdupcat(const char *str1, const char *str2)
return n; return n;
} }
char *BLI_strncpy(char *dst, const char *src, const int maxncpy) { char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy) {
int srclen= strlen(src); size_t srclen= strlen(src);
int cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen; size_t cpylen= (srclen>(maxncpy-1))?(maxncpy-1):srclen;
memcpy(dst, src, cpylen); memcpy(dst, src, cpylen);
dst[cpylen]= '\0'; dst[cpylen]= '\0';
@ -81,9 +81,9 @@ char *BLI_strncpy(char *dst, const char *src, const int maxncpy) {
return dst; return dst;
} }
int BLI_snprintf(char *buffer, size_t count, const char *format, ...) size_t BLI_snprintf(char *buffer, size_t count, const char *format, ...)
{ {
int n; size_t n;
va_list arg; va_list arg;
va_start(arg, format); va_start(arg, format);
@ -128,7 +128,7 @@ char *BLI_sprintfN(const char *format, ...)
*/ */
char *BLI_getQuotedStr (const char *str, const char *prefix) char *BLI_getQuotedStr (const char *str, const char *prefix)
{ {
int prefixLen = strlen(prefix); size_t prefixLen = strlen(prefix);
char *startMatch, *endMatch; char *startMatch, *endMatch;
/* get the starting point (i.e. where prefix starts, and add prefixLen+1 to it to get be after the first " */ /* get the starting point (i.e. where prefix starts, and add prefixLen+1 to it to get be after the first " */
@ -138,7 +138,7 @@ char *BLI_getQuotedStr (const char *str, const char *prefix)
endMatch= strchr(startMatch, '"'); // " NOTE: this comment here is just so that my text editor still shows the functions ok... endMatch= strchr(startMatch, '"'); // " NOTE: this comment here is just so that my text editor still shows the functions ok...
/* return the slice indicated */ /* return the slice indicated */
return BLI_strdupn(startMatch, (int)(endMatch-startMatch)); return BLI_strdupn(startMatch, (size_t)(endMatch-startMatch));
} }
/* Replaces all occurances of oldText with newText in str, returning a new string that doesn't /* Replaces all occurances of oldText with newText in str, returning a new string that doesn't
@ -149,7 +149,7 @@ char *BLI_getQuotedStr (const char *str, const char *prefix)
char *BLI_replacestr(char *str, const char *oldText, const char *newText) char *BLI_replacestr(char *str, const char *oldText, const char *newText)
{ {
DynStr *ds= NULL; DynStr *ds= NULL;
int lenOld= strlen(oldText); size_t lenOld= strlen(oldText);
char *match; char *match;
/* sanity checks */ /* sanity checks */
@ -263,10 +263,10 @@ int BLI_strcasecmp(const char *s1, const char *s2) {
return 0; return 0;
} }
int BLI_strncasecmp(const char *s1, const char *s2, int n) { int BLI_strncasecmp(const char *s1, const char *s2, size_t len) {
int i; int i;
for (i=0; i<n; i++) { for (i=0; i<len; i++) {
char c1 = tolower(s1[i]); char c1 = tolower(s1[i]);
char c2 = tolower(s2[i]); char c2 = tolower(s2[i]);