Merge branch 'stb_h_fix'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents e0dafae, 820f63b · Browse files · 3 files·+89 added−37 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+89 added−37 removed
- tests:+1 added−1 removed
- other:+88 added−36 removed
Provenance
- Commit
ec3fecd- Tree
73774fa- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent 1
e0dafae- Parent 2
820f63b
3 files changed+89 added−37 removed
modified:tests/stb.dsp+1 added-1 removed
64 unmodified lines65 # PROP Intermediate_Dir "Debug\stb"66 # PROP Ignore_Export_Lib 067 # PROP Target_Dir ""68 # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c69-# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "VORBIS_TEST" /FR /FD /GZ /c69+# ADD CPP /nologo /MTd /W3 /GX /Zi /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "MAIN_TEST" /FR /FD /GZ /c70 # SUBTRACT CPP /YX71 # ADD BASE RSC /l 0x409 /d "_DEBUG"72 # ADD RSC /l 0x409 /d "_DEBUG"73 BSC32=bscmake.exe115 unmodified linesmodified:stb_tilemap_editor.h+6 added-2 removed
1-// stb_tilemap_editor.h - v0.36 - Sean Barrett - http://nothings.org/stb1+// stb_tilemap_editor.h - v0.37 - Sean Barrett - http://nothings.org/stb2 // placed in the public domain - not copyrighted - first released 2014-093 //4 // Embeddable tilemap editor for C/C++5 //252 unmodified lines258 // #define STBTE_MAX_LAYERS 8 // max 32259 // #define STBTE_MAX_CATEGORIES 100260 // #define STBTE_UNDO_BUFFER_BYTES (1 << 24) // 16 MB261 // #define STBTE_MAX_COPY 90000 // e.g. 300x300262-// #define STBTE_MAX_PROPERTIESERTIES 10 // max properties per tile262+// #define STBTE_MAX_PROPERTIES 10 // max properties per tile263 //264 // API265 //266 // Further documentation appears in the header-file section below.7 unmodified lines274 // stbte_tilemap keeps its own undo state. (The clipboard is global, so275 // either approach allows cut&pasting between levels.)276 //277 // REVISION HISTORY278+// 0.37 fix warning279 // 0.36 minor compiler support280 // 0.35 layername button changes281 // - layername buttons grow with the layer panel282 // - fix stbte_create_map being declared as stbte_create28 unmodified lines311 // Additional features:312 // Josh Huelsman313 // Bugfixes:314 // Ryan Whitworth315+// Eugene Opalev316 //317 // LICENSE318 //319 // This software is in the public domain. Where that dedication is not9 unmodified lines329 #ifndef STB_TILEMAP_INCLUDE_STB_TILEMAP_EDITOR_H330 #define STB_TILEMAP_INCLUDE_STB_TILEMAP_EDITOR_H331 332 #ifdef _WIN32333+ #ifndef _CRT_SECURE_NO_WARNINGS334 #define _CRT_SECURE_NO_WARNINGS335+ #endif336 #include <stdlib.h>337 #include <stdio.h>338 #endif339 3792 unmodified linesmodified:stb.h+82 added-34 removed
1-/* stb.h - v2.25 - Sean's Tool Box -- public domain -- http://nothings.org/stb.h1+/* stb.h - v2.26 - Sean's Tool Box -- public domain -- http://nothings.org/stb.h2 no warranty is offered or implied; use this code at your own risk3 4 This is a single header file with a bunch of useful utilities5 for getting stuff done in C/C++.18 unmodified lines24 25 26 Version History27 28+ 2.26 various warning & buffixes29 2.25 various warning & bugfixes30 2.24 various warning & bugfixes31 2.23 fix 2.2232 2.22 64-bit fixes from '!='; fix stb_sdict_copy() to have preferred name153 unmodified lines186 blackpawn187 Mojofreem@github188 Ryan Whitworth189 Vincent Isambart190+ Mike Sartain191+ Eugene Opalev192+ Tim Sjostrand193 */194 195 #ifndef STB__INCLUDE_STB_H196 #define STB__INCLUDE_STB_H12 unmodified lines209 #define STB_THREADS210 #endif211 #endif212 209-#ifdef _WIN32213+#if defined(_WIN32) && !defined(__MINGW32__)214+ #ifndef _CRT_SECURE_NO_WARNINGS215 #define _CRT_SECURE_NO_WARNINGS216+ #endif217+ #ifndef _CRT_NONSTDC_NO_DEPRECATE218 #define _CRT_NONSTDC_NO_DEPRECATE219+ #endif220+ #ifndef _CRT_NON_CONFORMING_SWPRINTFS221 #define _CRT_NON_CONFORMING_SWPRINTFS222+ #endif223 #if !defined(_MSC_VER) || _MSC_VER > 1700224 #include <intrin.h> // _BitScanReverse225 #endif226 #endif496 unmodified lines723 724 STB_EXTERN void stbprint(const char *fmt, ...);725 STB_EXTERN char *stb_sprintf(const char *fmt, ...);726 STB_EXTERN char *stb_mprintf(const char *fmt, ...);727+STB_EXTERN int stb_snprintf(char *s, size_t n, const char *fmt, ...);728+STB_EXTERN int stb_vsnprintf(char *s, size_t n, const char *fmt, va_list v);729 730 #ifdef STB_DEFINE731+int stb_vsnprintf(char *s, size_t n, const char *fmt, va_list v)732+{733+ int res;734+ #ifdef _WIN32735+ // Could use "_vsnprintf_s(s, n, _TRUNCATE, fmt, v)" ?736+ res = _vsnprintf(s,n,fmt,v);737+ #else738+ res = vsnprintf(s,n,fmt,v);739+ #endif740+ if (n) s[n-1] = 0;741+ // Unix returns length output would require, Windows returns negative when truncated.742+ return (res >= (int) n || res < 0) ? -1 : res;743+}744+745+int stb_snprintf(char *s, size_t n, const char *fmt, ...)746+{747+ int res;748+ va_list v;749+ va_start(v,fmt);750+ res = stb_vsnprintf(s, n, fmt, v);751+ va_end(v);752+ return res;753+}754+755 char *stb_sprintf(const char *fmt, ...)756 {757 static char buffer[1024];758 va_list v;759 va_start(v,fmt);724- #ifdef _WIN32725- _vsnprintf(buffer, 1024, fmt, v);760+ stb_vsnprintf(buffer,1024,fmt,v);726- #else727- vsnprintf(buffer, 1024, fmt, v);728- #endif761 va_end(v);730- buffer[1023] = 0;762 return buffer;763 }764 765 char *stb_mprintf(const char *fmt, ...)766 {767 static char buffer[1024];768 va_list v;769 va_start(v,fmt);739- #ifdef _WIN32740- _vsnprintf(buffer, 1024, fmt, v);770+ stb_vsnprintf(buffer,1024,fmt,v);741- #else742- vsnprintf(buffer, 1024, fmt, v);743- #endif771 va_end(v);745- buffer[1023] = 0;772 return strdup(buffer);773 }774 775 #ifdef _WIN3291 unmodified lines867 char *tbuf = buffer;868 va_list v;869 870 va_start(v,fmt);845- res = _vsnprintf(buffer, sizeof(buffer), fmt, v);871+ res = stb_vsnprintf(buffer, sizeof(buffer), fmt, v);872 va_end(v);847- buffer[sizeof(buffer)-1] = 0;873 874 if (res < 0) {875 tbuf = (char *) malloc(16384);876 va_start(v,fmt);912 unmodified lines1789 STB_EXTERN char * stb_strichr(char *s, char t);1790 STB_EXTERN char * stb_stristr(char *s, char *t);1791 STB_EXTERN int stb_prefix_count(char *s, char *t);1792 STB_EXTERN char * stb_plural(int n); // "s" or ""1793+STB_EXTERN size_t stb_strscpy(char *d, const char *s, size_t n);1794 1795 STB_EXTERN char **stb_tokens(char *src, char *delimit, int *count);1796 STB_EXTERN char **stb_tokens_nested(char *src, char *delimit, int *count, char *nest_in, char *nest_out);1797 STB_EXTERN char **stb_tokens_nested_empty(char *src, char *delimit, int *count, char *nest_in, char *nest_out);6 unmodified lines1804 // appear back to back, in which case they're considered escaped)1805 1806 #ifdef STB_DEFINE1807 1808+size_t stb_strscpy(char *d, const char *s, size_t n)1809+{1810+ size_t len = strlen(s);1811+ if (len >= n) {1812+ if (n) d[0] = 0;1813+ return 0;1814+ }1815+ strcpy(d,s);1816+ return len + 1;1817+}1818+1819 char *stb_plural(int n)1820 {1821 return n == 1 ? "" : "s";1822 }1275 unmodified lines3098 // add N new uninitialized elements starting at index 'i'3099 #define stb_arr_insertn(a,i,n) (stb__arr_insertn((void **) &(a), sizeof(*a), i, n))3100 3101 // insert an element at i3065-#define stb_arr_insert(a,i,v) (stb__arr_insertn((void **) &(a), sizeof(*a), i, n), ((a)[i] = v))3102+#define stb_arr_insert(a,i,v) (stb__arr_insertn((void **) &(a), sizeof(*a), i, 1), ((a)[i] = v))3103 3104 // delete N elements from the middle starting at index 'i'3105 #define stb_arr_deleten(a,i,n) (stb__arr_deleten((void **) &(a), sizeof(*a), i, n))3106 177 unmodified lines3284 return;3285 }3286 3287 z = stb_arr_len2(p);3251- stb__arr_addlen_(&p, size, i STB__ARGS);3288+ stb__arr_addlen_(&p, size, n STB__ARGS);3289 memmove((char *) p + (i+n)*size, (char *) p + i*size, size * (z-i));3290 }3291 *pp = p;3292 }1 unmodified line3294 void stb__arr_deleten_(void **pp, int size, int i, int n STB__PARAMS)3295 {3296 void *p = *pp;3297 if (n) {3261- memmove((char *) p + i*size, (char *) p + (i+n)*size, size * (stb_arr_len2(p)-i));3298+ memmove((char *) p + i*size, (char *) p + (i+n)*size, size * (stb_arr_len2(p)-(i+n)));3299 stb_arrhead2(p)->len -= n;3300 }3301 *pp = p;3302 }2596 unmodified lines5899 free(f2[i]);5900 stb_arr_free(f2);5901 }5902 5903+static int isdotdirname(char *name)5904+{5905+ if (name[0] == '.')5906+ return (name[1] == '.') ? !name[2] : !name[1];5907+ return 0;5908+}5909+5910 STB_EXTERN int stb_wildmatchi(char *expr, char *candidate);5911 static char **readdir_raw(char *dir, int return_subdirs, char *mask)5912 {5913 char **results = NULL;5870- char buffer[512], with_slash[512];5914+ char buffer[4096], with_slash[4096];5915 size_t n;5916 5917 #ifdef _MSC_VER5918 stb__wchar *ws;9 unmodified lines5928 const DIR *none = NULL;5929 DIR *z;5930 #endif5931 5888- strcpy(buffer,dir);5932+ n = stb_strscpy(buffer,dir,sizeof(buffer));5933+ if (!n || n >= sizeof(buffer))5934+ return NULL;5935 stb_fixpath(buffer);5890- n = strlen(buffer);5936+ n--;5937 5938 if (n > 0 && (buffer[n-1] != '/')) {5939 buffer[n++] = '/';5940 }5941 buffer[n] = 0;5896- strcpy(with_slash, buffer);5942+ if (!stb_strscpy(with_slash,buffer,sizeof(with_slash)))5943+ return NULL;5944 5945 #ifdef _MSC_VER5899- strcpy(buffer+n, "*.*");5946+ if (!stb_strscpy(buffer+n,"*.*",sizeof(buffer)-n))5947+ return NULL;5948 ws = stb__from_utf8(buffer);5949 z = _wfindfirst((const wchar_t *)ws, &data);5950 #else5951 z = opendir(dir);5952 #endif5953 5906-5954 if (z != none) {5955 int nonempty = STB_TRUE;5956 #ifndef _MSC_VER5957 struct dirent *data = readdir(z);12 unmodified lines5970 }5971 is_subdir = !!(data.attrib & _A_SUBDIR);5972 #else5973 char *name = data->d_name;5927- strcpy(buffer+n,name);5928- DIR *y = opendir(buffer);5929- is_subdir = (y != NULL);5930- if (y != NULL) closedir(y);5974+ if (!stb_strscpy(buffer+n,name,sizeof(buffer)-n))5975+ break;5976+ // Could follow DT_LNK, but would need to check for recursive links.5977+ is_subdir = !!(data->d_type & DT_DIR);5978 #endif5932- 5979+5980 if (is_subdir == return_subdirs) {5934- if (!is_subdir || name[0] != '.') {5981+ if (!is_subdir || !isdotdirname(name)) {5982 if (!mask || stb_wildmatchi(mask, name)) {5936- char buffer[512],*p=buffer;5937- sprintf(buffer, "%s%s", with_slash, name);5983+ char buffer[4096],*p=buffer;5984+ if ( stb_snprintf(buffer, sizeof(buffer), "%s%s", with_slash, name) < 0 )5985+ break;5986 if (buffer[0] == '.' && buffer[1] == '/')5987 p = buffer+2;5988 stb_arr_push(results, strdup(p));5989 }1843 unmodified lines7833 7834 void ** stb_ps_getlist(stb_ps *ps, int *count)7835 {7836 int i,n=0;7789- void **p;7837+ void **p = NULL;7838 switch (3 & (int) ps) {7839 case STB_ps_direct:7840 if (ps == NULL) { *count = 0; return NULL; }7841 p = (void **) malloc(sizeof(*p) * 1);6343 unmodified lines