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>2018-06-11 11:43:34 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-06-11 11:46:02 +0300
commit9e8bd3a072cff37fcc7808bdbefa1fb78ab94c22 (patch)
tree9b30d278beb427e33fb47b6f999f72b38c53a8de /source/blender/blenlib
parent1d8d4e03f51e22cd309dbb3297b13711d84491e8 (diff)
path_util: avoid overflow w/ strtoll use
Also style cleanup.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/path_util.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index f59ef7fd39f..a3651de73a2 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -83,7 +83,7 @@ static bool BLI_path_is_abs(const char *name);
* \param tail Optional area to return copy of part of string following digits, or from dot if no digits.
* \param numlen Optional to return number of digits found.
*/
-int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *numlen)
+int BLI_stringdec(const char *string, char *head, char *tail, ushort *r_num_len)
{
uint nums = 0, nume = 0;
int i;
@@ -93,8 +93,12 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu
const uint lslash_len = lslash != NULL ? (int)(lslash - string) : 0;
uint name_end = string_len;
- while (name_end > lslash_len && string[--name_end] != '.') {} /* name ends at dot if present */
- if (name_end == lslash_len && string[name_end] != '.') name_end = string_len;
+ while (name_end > lslash_len && string[--name_end] != '.') {
+ /* name ends at dot if present */
+ }
+ if (name_end == lslash_len && string[name_end] != '.') {
+ name_end = string_len;
+ }
for (i = name_end - 1; i >= (int)lslash_len; i--) {
if (isdigit(string[i])) {
@@ -113,28 +117,34 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu
}
if (found_digit) {
- char *ptr;
- long ret;
- ret = strtoll(&(string[nums]), &ptr, 10);
+ const long long int ret = strtoll(&(string[nums]), NULL, 10);
if (ret >= INT_MIN && ret <= INT_MAX) {
- if (tail) strcpy(tail, &string[nume + 1]);
+ if (tail) {
+ strcpy(tail, &string[nume + 1]);
+ }
if (head) {
strcpy(head, string);
head[nums] = 0;
}
- if (numlen) *numlen = nume - nums + 1;
- return ((int)ret);
+ if (r_num_len) {
+ *r_num_len = nume - nums + 1;
+ }
+ return (int)ret;
}
}
- if (tail) strcpy(tail, string + name_end);
+ if (tail) {
+ strcpy(tail, string + name_end);
+ }
if (head) {
/* name_end points to last character of head,
* make it +1 so null-terminator is nicely placed
*/
BLI_strncpy(head, string, name_end + 1);
}
- if (numlen) *numlen = 0;
+ if (r_num_len) {
+ *r_num_len = 0;
+ }
return 0;
}