From 41d1dcc0299ffe54da1913fa232d4a87b01ef3c8 Mon Sep 17 00:00:00 2001 From: Brian Collins <60075820+bcollins526@users.noreply.github.com> Date: Sun, 19 Jan 2020 13:06:11 -0800 Subject: [PATCH 1/4] changed buffer to path for STB_EXT_NO_PERIOD, and specified appropriate buffer size for the copy (sizeof(buffer) referred to the size of the buffer pointer, which was incorrect) --- stb.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stb.h b/stb.h index a853d08..e275d5a 100644 --- a/stb.h +++ b/stb.h @@ -2439,7 +2439,7 @@ static char *stb__splitpath_raw(char *buffer, char *path, int flag) } else { x = f2; if (flag & STB_EXT_NO_PERIOD) - if (buffer[x] == '.') + if (path[x] == '.') ++x; } @@ -2456,7 +2456,7 @@ static char *stb__splitpath_raw(char *buffer, char *path, int flag) } if (len) { stb_p_strcpy_s(buffer, sizeof(buffer), "./"); return buffer; } - stb_p_strncpy_s(buffer, sizeof(buffer),path+x, y-x); + stb_p_strncpy_s(buffer, y-x+1, path+x, y-x); buffer[y-x] = 0; return buffer; } From 7c44b159039c3fb1bba2947f411f4bf10885e729 Mon Sep 17 00:00:00 2001 From: Brian Collins <60075820+bcollins526@users.noreply.github.com> Date: Sun, 19 Jan 2020 13:43:43 -0800 Subject: [PATCH 2/4] forgot to update fixes list --- stb.h | 1 + 1 file changed, 1 insertion(+) diff --git a/stb.h b/stb.h index e275d5a..9127d5c 100644 --- a/stb.h +++ b/stb.h @@ -200,6 +200,7 @@ CREDITS github:infatum Dave Butler (Croepha) Ethan Lee (flibitijibibo) + Brian Collins */ #include From 8fca192660f66f284017e74eca7ffcb8bbf7bbe3 Mon Sep 17 00:00:00 2001 From: Brian Collins <60075820+bcollins526@users.noreply.github.com> Date: Sun, 19 Jan 2020 14:38:09 -0800 Subject: [PATCH 3/4] better to just use stb_strncpy inside stb__splitpath_raw, also fixed an indexing bug in stb_strncpy itself. --- stb.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stb.h b/stb.h index 9127d5c..db53907 100644 --- a/stb.h +++ b/stb.h @@ -2009,7 +2009,7 @@ char *stb_trimwhite(char *s) char *stb_strncpy(char *s, char *t, int n) { stb_p_strncpy_s(s,n+1,t,n); - s[n-1] = 0; + s[n] = 0; return s; } @@ -2457,8 +2457,7 @@ static char *stb__splitpath_raw(char *buffer, char *path, int flag) } if (len) { stb_p_strcpy_s(buffer, sizeof(buffer), "./"); return buffer; } - stb_p_strncpy_s(buffer, y-x+1, path+x, y-x); - buffer[y-x] = 0; + stb_strncpy(buffer, path+x, y-x); return buffer; } From d5d052c806eee2ca1f858cb58b2f062d9fa25b90 Mon Sep 17 00:00:00 2001 From: Brian Collins <60075820+bcollins526@users.noreply.github.com> Date: Sun, 26 Jan 2020 15:06:32 -0800 Subject: [PATCH 4/4] casting to int to remove ptrdiff_t <-> int comparison warnings --- stb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb.h b/stb.h index db53907..adfe33d 100644 --- a/stb.h +++ b/stb.h @@ -2457,7 +2457,7 @@ static char *stb__splitpath_raw(char *buffer, char *path, int flag) } if (len) { stb_p_strcpy_s(buffer, sizeof(buffer), "./"); return buffer; } - stb_strncpy(buffer, path+x, y-x); + stb_strncpy(buffer, path+int(x), int(y-x)); return buffer; }