blob: 20d4b65e263085ac317cc8d6cd94fa0e36eb4a4d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
fix from https://gitlab.xiph.org/xiph/vorbis-tools/-/merge_requests/7
diff --git a/oggenc/platform.c b/oggenc/platform.c
index 6d9f4ef..b66e47a 100644
--- a/oggenc/platform.c
+++ b/oggenc/platform.c
@@ -136,18 +136,22 @@ int create_directories(char *fn, int isutf8)
{
char *end, *start;
struct stat statbuf;
- char *segment = malloc(strlen(fn)+1);
+ const size_t fn_len = strlen(fn);
+ char *segment = malloc(fn_len+1);
#ifdef _WIN32
wchar_t seg[MAX_PATH+1];
#endif
start = fn;
#ifdef _WIN32
- if(strlen(fn) >= 3 && isalpha(fn[0]) && fn[1]==':')
+ // Strip drive prefix
+ if(fn_len >= 3 && isalpha(fn[0]) && fn[1]==':') {
+
start = start+2;
#endif
- while((end = strpbrk(start+1, PATH_SEPS)) != NULL)
+ // Loop through path segments, creating directories if necessary
+ while((end = strpbrk(start + strspn(start, PATH_SEPS), PATH_SEPS)) != NULL)
{
int rv;
memcpy(segment, fn, end-fn);
|