X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=common.c;h=f4e459af3e104d8a883a3a1447f86f19f044fa2a;hb=7b96ec0f365f5c9662a831d9eba2b87d3f0cbb18;hp=0f0572d35302d890d7a80bae6ec1e1c312a7c7df;hpb=26a665ff43052862131df3c63785f91861989fc8;p=xonotic%2Fdarkplaces.git diff --git a/common.c b/common.c index 0f0572d3..f4e459af 100644 --- a/common.c +++ b/common.c @@ -460,7 +460,7 @@ Parse a token out of a string Writes the token and its strlen to the com_token and com_token_len globals. ============== */ -int COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments) +qbool COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments) { int len; int c; @@ -578,7 +578,7 @@ Parse a token out of a string Writes the token and its strlen to the com_token and com_token_len globals. ============== */ -int COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline) +qbool COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline) { int len; int c; @@ -697,7 +697,7 @@ Parse a token out of a string Writes the token and its strlen to the com_token and com_token_len globals. ============== */ -int COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline) +qbool COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline) { int len; int c; @@ -816,7 +816,7 @@ Parse a token out of a string, behaving like the qwcl console Writes the token and its strlen to the com_token and com_token_len globals. ============== */ -int COM_ParseToken_Console(const char **datapointer) +qbool COM_ParseToken_Console(const char **datapointer) { int len; const char *data = *datapointer; @@ -1021,9 +1021,9 @@ int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list ar buffer[buffersize - 1] = '\0'; // we could be inside Con_Printf if (result < 0) - Sys_Printf("dpvsnprintf: output error, buffer size %zu\n", buffersize); + Sys_Printf("dpvsnprintf: output error, buffer size %lu\n", (unsigned long)buffersize); else - Sys_Printf("dpvsnprintf: truncated to %zu bytes: \"%s\"\n", buffersize - 1, buffer); + Sys_Printf("dpvsnprintf: truncated to %lu bytes: \"%s\"\n", (unsigned long)buffersize - 1, buffer); return -1; } @@ -1345,7 +1345,8 @@ copy one byte at a time (even at -O3) and its advantage increases with string le #ifdef WIN32 // memccpy() is standard in POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD, C23. // Microsoft supports it, but apparently complains if we use it. - #pragma warning(disable : 4996) + #undef memccpy + #define memccpy _memccpy #endif /** Chain-copies a string with truncation and efficiency (compared to strlcat()). @@ -1361,7 +1362,7 @@ char *dp_stpecpy(char *dst, char *end, const char *src) if (p) return p - 1; end[-1] = '\0'; - Con_Printf(CON_WARN "%s: src string unterminated or truncated to %zu bytes: \"%s\"\n", __func__, dst == end ? 0 : (end - dst) - 1, dst); + Con_Printf(CON_WARN "%s: src string unterminated or truncated to %lu bytes: \"%s\"\n", __func__, (unsigned long)(dst == end ? 0 : (end - dst) - 1), dst); return end; } @@ -1369,16 +1370,16 @@ char *dp_stpecpy(char *dst, char *end, const char *src) * Returns a pointer to the \0 terminator. Guarantees \0 termination. * Compared to ustr2stp(): truncates and warns on overflow. */ -char *dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t ssize) +char *dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t slen) { - if (ssize >= dsize) + if (slen >= dsize) { - ssize = dsize - 1; - Con_Printf(CON_WARN "%s: src string truncated to %zu bytes: \"%.*s\"\n", __func__, ssize, (int)ssize, src); + slen = dsize - 1; + Con_Printf(CON_WARN "%s: src string truncated to %lu bytes: \"%.*s\"\n", __func__, (unsigned long)slen, (int)slen, src); } - memcpy(dst, src, ssize); - dst[ssize] = '\0'; - return &dst[ssize]; + memcpy(dst, src, slen); + dst[slen] = '\0'; + return &dst[slen]; } /** Copies a string, like strlcpy() but with a better return: the number of bytes copied @@ -1394,7 +1395,7 @@ size_t dp__strlcpy(char *dst, const char *src, size_t dsize, const char *func, u if (p) return (p - 1) - dst; dst[dsize - 1] = '\0'; - Con_Printf(CON_WARN "%s:%u: src string unterminated or truncated to %zu bytes: \"%s\"\n", func, line, dsize - 1, dst); + Con_Printf(CON_WARN "%s:%u: src string unterminated or truncated to %lu bytes: \"%s\"\n", func, line, (unsigned long)dsize - 1, dst); return dsize - 1; } @@ -1406,9 +1407,12 @@ size_t dp__strlcpy(char *dst, const char *src, size_t dsize, const char *func, u */ size_t dp__strlcat(char *dst, const char *src, size_t dsize, const char *func, unsigned line) { - char *p = (char *)memchr(dst, '\0', dsize) ?: dst; - size_t offset = p - dst; + size_t offset; + char *p = (char *)memchr(dst, '\0', dsize); + if (!p) + p = dst; + offset = p - dst; return dp__strlcpy(p, src, dsize - offset, func, line) + offset; }