Skip to content
Snippets Groups Projects
Commit a0d535a8 authored by John Hodge's avatar John Hodge
Browse files

Fixing vsnprintf behavior on 64-bit systems

parent 7584f0ce
Branches
Tags
No related merge requests found
BUILD_NUM = 213 BUILD_NUM = 215
...@@ -657,7 +657,8 @@ void VT_SetTerminal(int ID) ...@@ -657,7 +657,8 @@ void VT_SetTerminal(int ID)
tVideo_IOCtl_Pos pos; tVideo_IOCtl_Pos pos;
pos.x = (gpVT_CurTerm->WritePos - gpVT_CurTerm->ViewPos) % gpVT_CurTerm->TextWidth; pos.x = (gpVT_CurTerm->WritePos - gpVT_CurTerm->ViewPos) % gpVT_CurTerm->TextWidth;
pos.y = (gpVT_CurTerm->WritePos - gpVT_CurTerm->ViewPos) / gpVT_CurTerm->TextWidth; pos.y = (gpVT_CurTerm->WritePos - gpVT_CurTerm->ViewPos) / gpVT_CurTerm->TextWidth;
VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos); if( pos.x < gpVT_CurTerm->TextHeight )
VFS_IOCtl(giVT_OutputDevHandle, VIDEO_IOCTL_SETCURSOR, &pos);
} }
if( gpVT_CurTerm->Mode == TERM_MODE_TEXT ) if( gpVT_CurTerm->Mode == TERM_MODE_TEXT )
......
...@@ -178,6 +178,10 @@ void itoa(char *buf, Uint num, int base, int minLength, char pad) ...@@ -178,6 +178,10 @@ void itoa(char *buf, Uint num, int base, int minLength, char pad)
if(pos==__maxlen){return pos;}\ if(pos==__maxlen){return pos;}\
if(__s){__s[pos++]=ch;}else{pos++;}\ if(__s){__s[pos++]=ch;}else{pos++;}\
}while(0) }while(0)
#define GETVAL() do {\
if(isLongLong) val = va_arg(args, Uint64);\
else val = va_arg(args, unsigned int);\
}while(0)
/** /**
* \brief VArg String Number Print Formatted * \brief VArg String Number Print Formatted
*/ */
...@@ -215,9 +219,6 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -215,9 +219,6 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
goto printString; goto printString;
} }
// Get Argument
val = va_arg(args, unsigned int);
// - Padding Side Flag // - Padding Side Flag
if(c == '+') { if(c == '+') {
bPadLeft = 1; bPadLeft = 1;
...@@ -234,8 +235,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -234,8 +235,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
// - Minimum length // - Minimum length
if(c == '*') { // Dynamic length if(c == '*') { // Dynamic length
minSize = val; minSize = va_arg(args, unsigned int);
val = va_arg(args, unsigned int);
c = *__format++; c = *__format++;
} }
else if('1' <= c && c <= '9') else if('1' <= c && c <= '9')
...@@ -257,9 +257,6 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -257,9 +257,6 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
{ {
c = *__format++; c = *__format++;
if(c == 'l') { if(c == 'l') {
#if BITS == 32
val |= (Uint64)va_arg(args, Uint) << 32;
#endif
c = *__format++; c = *__format++;
isLongLong = 1; isLongLong = 1;
} }
...@@ -271,6 +268,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -271,6 +268,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
{ {
case 'd': case 'd':
case 'i': case 'i':
GETVAL();
if( isLongLong && val >> 63 ) { if( isLongLong && val >> 63 ) {
PUTCH('-'); PUTCH('-');
val = -val; val = -val;
...@@ -282,26 +280,31 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -282,26 +280,31 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
itoa(p, val, 10, minSize, pad); itoa(p, val, 10, minSize, pad);
goto printString; goto printString;
case 'u': case 'u':
GETVAL();
itoa(p, val, 10, minSize, pad); itoa(p, val, 10, minSize, pad);
goto printString; goto printString;
case 'x': case 'x':
GETVAL();
itoa(p, val, 16, minSize, pad); itoa(p, val, 16, minSize, pad);
goto printString; goto printString;
case 'o': case 'o':
GETVAL();
itoa(p, val, 8, minSize, pad); itoa(p, val, 8, minSize, pad);
goto printString; goto printString;
case 'b': case 'b':
GETVAL();
itoa(p, val, 2, minSize, pad); itoa(p, val, 2, minSize, pad);
goto printString; goto printString;
case 'B': //Boolean case 'B': //Boolean
val = va_arg(args, unsigned int);
if(val) p = "True"; if(val) p = "True";
else p = "False"; else p = "False";
goto printString; goto printString;
// String - Null Terminated Array // String - Null Terminated Array
case 's': case 's':
p = (char*)(tVAddr)val; p = va_arg(args, char*); // Get Argument
printString: printString:
if(!p) p = "(null)"; if(!p) p = "(null)";
len = strlen(p); len = strlen(p);
...@@ -311,7 +314,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -311,7 +314,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
break; break;
case 'C': // Non-Null Terminated Character Array case 'C': // Non-Null Terminated Character Array
p = (char*)(tVAddr)val; p = va_arg(args, char*);
if(!p) goto printString; if(!p) goto printString;
while(minSize--) PUTCH(*p++); while(minSize--) PUTCH(*p++);
break; break;
...@@ -319,6 +322,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args) ...@@ -319,6 +322,7 @@ int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
// Single Character // Single Character
case 'c': case 'c':
default: default:
GETVAL();
PUTCH( (Uint8)val ); PUTCH( (Uint8)val );
break; break;
} }
......
...@@ -1146,7 +1146,7 @@ void Mutex_Acquire(tMutex *Mutex) ...@@ -1146,7 +1146,7 @@ void Mutex_Acquire(tMutex *Mutex)
Mutex->Waiting = us; Mutex->Waiting = us;
Mutex->LastWaiting = us; Mutex->LastWaiting = us;
} }
#if 1 #if 0
{ {
int i = 0; int i = 0;
tThread *t; tThread *t;
......
...@@ -519,7 +519,7 @@ void Vesa_FlipCursor(void *Arg) ...@@ -519,7 +519,7 @@ void Vesa_FlipCursor(void *Arg)
// Sanity 1 // Sanity 1
if(giVesaCursorX < 0 || giVesaCursorY < 0 if(giVesaCursorX < 0 || giVesaCursorY < 0
|| y*pitch + x + giVT_CharHeight*pitch > (int)gpVesaCurMode->fbSize/4) { || y*pitch + x + giVT_CharHeight*pitch > (int)gpVesaCurMode->fbSize/4) {
Debug("Cursor OOB (%i,%i)", x, y); Log_Notice("VESA", "Cursor OOB (%i,%i)", x, y);
giVesaCursorTimer = -1; giVesaCursorTimer = -1;
return; return;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment