]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
VM_sprintf: use intmax_t for integer types
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 20 Apr 2012 08:46:33 +0000 (08:46 +0000)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 13 May 2012 19:17:41 +0000 (21:17 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11810 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=08798068fc28f075e3c8b6abb5bee2bbda3c25a8

host.c
prvm_cmds.c
quakedef.h

diff --git a/host.c b/host.c
index ef7ee4081e2f2baed8e0f196583077c41d682667..72ed8b9833276176d2a10a9878b5cc5e4594528a 100644 (file)
--- a/host.c
+++ b/host.c
@@ -97,6 +97,7 @@ Host_AbortCurrentFrame
 aborts the current host frame and goes on with the next one
 ================
 */
+void Host_AbortCurrentFrame(void) DP_FUNC_NORETURN;
 void Host_AbortCurrentFrame(void)
 {
        // in case we were previously nice, make us mean again
index f6f40ad5555a9d9d9919a93bc22aec0d6fc6c4fb..f18bff240593b002c78ca067658b465b9e476374 100644 (file)
@@ -6433,6 +6433,7 @@ void VM_sprintf(prvm_prog_t *prog)
        const char *s, *s0;
        char outbuf[MAX_INPUTLINE];
        char *o = outbuf, *end = outbuf + sizeof(outbuf), *err;
+       const char *p;
        int argpos = 1;
        int width, precision, thisarg, flags;
        char formatbuf[16];
@@ -6639,6 +6640,12 @@ nolength:
                                        if(flags & PRINTF_LEFT) *f++ = '-';
                                        if(flags & PRINTF_SPACEPOSITIVE) *f++ = ' ';
                                        if(flags & PRINTF_SIGNPOSITIVE) *f++ = '+';
+                                       if(*s == 'd' || *s == 'i' || *s == 'o' || *s == 'u' || *s == 'x' || *s == 'X')
+                                       {
+                                               // make it use a good integer type
+                                               for(p = INT_LOSSLESS_FORMAT_SIZE; *p; )
+                                                       *f++ = *p++;
+                                       }
                                        *f++ = '*';
                                        if(precision >= 0)
                                        {
@@ -6655,15 +6662,15 @@ nolength:
                                        {
                                                case 'd': case 'i':
                                                        if(precision < 0) // not set
-                                                               o += dpsnprintf(o, end - o, formatbuf, width, (isfloat ? (int) GETARG_FLOAT(thisarg) : (int) GETARG_INT(thisarg)));
+                                                               o += dpsnprintf(o, end - o, formatbuf, width, (isfloat ? INT_LOSSLESS_FORMAT_CONVERT_S(GETARG_FLOAT(thisarg)) : INT_LOSSLESS_FORMAT_CONVERT_S(GETARG_INT(thisarg))));
                                                        else
-                                                               o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (int) GETARG_FLOAT(thisarg) : (int) GETARG_INT(thisarg)));
+                                                               o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? INT_LOSSLESS_FORMAT_CONVERT_S(GETARG_FLOAT(thisarg)) : INT_LOSSLESS_FORMAT_CONVERT_S(GETARG_INT(thisarg))));
                                                        break;
                                                case 'o': case 'u': case 'x': case 'X':
                                                        if(precision < 0) // not set
-                                                               o += dpsnprintf(o, end - o, formatbuf, width, (isfloat ? (unsigned int) GETARG_FLOAT(thisarg) : (unsigned int) GETARG_INT(thisarg)));
+                                                               o += dpsnprintf(o, end - o, formatbuf, width, (isfloat ? INT_LOSSLESS_FORMAT_CONVERT_U(GETARG_FLOAT(thisarg)) : INT_LOSSLESS_FORMAT_CONVERT_U(GETARG_INT(thisarg))));
                                                        else
-                                                               o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (unsigned int) GETARG_FLOAT(thisarg) : (unsigned int) GETARG_INT(thisarg)));
+                                                               o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? INT_LOSSLESS_FORMAT_CONVERT_U(GETARG_FLOAT(thisarg)) : INT_LOSSLESS_FORMAT_CONVERT_U(GETARG_INT(thisarg))));
                                                        break;
                                                case 'e': case 'E': case 'f': case 'F': case 'g': case 'G':
                                                        if(precision < 0) // not set
index fd0f253ec9c9046aa8ce74d77a7d7af3e1ea945a..afa8aaa7d0af69a8678d0fa5926b0b55954a05fc 100644 (file)
@@ -563,5 +563,15 @@ void Sys_Shared_Init(void);
 #define VECTOR_LOSSLESS_FORMAT "%.9g %.9g %.9g"
 #endif
 
+#ifdef _MSC_VER
+#define INT_LOSSLESS_FORMAT_SIZE "I64"
+#define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((__int64)(x))
+#define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((unsigned __int64)(x))
+#else
+#define INT_LOSSLESS_FORMAT_SIZE "j"
+#define INT_LOSSLESS_FORMAT_CONVERT_S(x) ((intmax_t)(x))
+#define INT_LOSSLESS_FORMAT_CONVERT_U(x) ((uintmax_t)(x))
+#endif
+
 #endif