stb_sprintf: PR 613
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 · parent 81b4fd7 · Browse files · 1 file·+17 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+17 added−29 removed
- other:+17 added−29 removed
Provenance
- Commit
e802821- Tree
832eef7- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent
81b4fd7
1 file changed+17 added−29 removed
modified:stb_sprintf.h+17 added-29 removed
16 unmodified lines17 // Marcin Wojdyr18 // Leonard Ritter19 // Stefano Zanotti20 // Adam Allison21-// Kevin Schmidt21+// Arvid Gerstmann22 //23 // LICENSE:24 //25 // See end of file for license information.113 unmodified lines139 "%s%s%s" for 64 char strings (7.1x/7.3x faster)140 "...512 char string..." ( 35.0x/32.5x faster!)141 */142 143-#if defined(__clang__)144- #if defined(__has_feature) && defined(__has_attribute)145- #if __has_feature(address_sanitizer)146- #if __has_attribute(__no_sanitize__)147- #define STBSP__ASAN __attribute__((__no_sanitize__("address")))148- #elif __has_attribute(__no_sanitize_address__)149- #define STBSP__ASAN __attribute__((__no_sanitize_address__))150- #elif __has_attribute(__no_address_safety_analysis__)151- #define STBSP__ASAN __attribute__((__no_address_safety_analysis__))143+#if defined(__has_feature)144+ #if __has_feature(address_sanitizer)145+ #define STBI__ASAN __attribute__((no_sanitize("address")))146 #endif153- #endif154- #endif155-#elif __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)156- #if __SANITIZE_ADDRESS__157- #define STBSP__ASAN __attribute__((__no_sanitize_address__))158- #endif147 #endif160-#ifndef STBSP__ASAN161-#define STBSP__ASAN148+#ifndef STBI__ASAN149+#define STBI__ASAN150 #endif151 152 #ifdef STB_SPRINTF_STATIC153 #define STBSP__PUBLICDEC static166-#define STBSP__PUBLICDEF static STBSP__ASAN154+#define STBSP__PUBLICDEF static STBI__ASAN155 #else156 #ifdef __cplusplus157 #define STBSP__PUBLICDEC extern "C"170-#define STBSP__PUBLICDEF extern "C" STBSP__ASAN158+#define STBSP__PUBLICDEF extern "C" STBI__ASAN159 #else160 #define STBSP__PUBLICDEC extern173-#define STBSP__PUBLICDEF STBSP__ASAN161+#define STBSP__PUBLICDEF STBI__ASAN162 #endif163 #endif164 165 #include <stdarg.h> // for va_list()1176 unmodified lines1342 1343 typedef struct stbsp__context {1344 char *buf;1345 int count;1346+ int length;1347 char tmp[STB_SPRINTF_MIN];1348 } stbsp__context;1349 1350 static char *stbsp__clamp_callback(char *buf, void *user, int len)1351 {1352 stbsp__context *c = (stbsp__context *)user;1353+ c->length += len;1354 1355 if (len > c->count)1356 len = c->count;1357 11 unmodified lines1369 c->count -= len;1370 }1371 1372 if (c->count <= 0)1383- return 0;1373+ return c->tmp;1374 return (c->count >= STB_SPRINTF_MIN) ? c->buf : c->tmp; // go direct into buffer if you can1375 }1376 1377 static char * stbsp__count_clamp_callback( char * buf, void * user, int len )1378 {1379 stbsp__context * c = (stbsp__context*)user;1380 1391- c->count += len;1381+ c->length += len;1382 return c->tmp; // go direct into buffer if you can1383 }1384 1385 STBSP__PUBLICDEF int STB_SPRINTF_DECORATE( vsnprintf )( char * buf, int count, char const * fmt, va_list va )1386 {1387 stbsp__context c;1398- int l;1388 1389 if ( (count == 0) && !buf )1390 {1402- c.count = 0;1391+ c.length = 0;1392 1393 STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__count_clamp_callback, &c, c.tmp, fmt, va );1405- l = c.count;1394 }1395 else1396 {1409- if ( count == 0 )1410- return 0;1397+ int l;1398 1399 c.buf = buf;1400 c.count = count;1401+ c.length = 0;1402 1403 STB_SPRINTF_DECORATE( vsprintfcb )( stbsp__clamp_callback, &c, stbsp__clamp_callback(0,&c,0), fmt, va );1404 1405 // zero-terminate2 unmodified lines1408 l = count - 1;1409 buf[l] = 0;1410 }1411 1424- return l;1412+ return c.length;1413 }1414 1415 STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(snprintf)(char *buf, int count, char const *fmt, ...)1416 {445 unmodified lines