// === CODE ===
// - Import userland stroi.c file
#define _LIB_H_
+#define _SysDebug(f,v...) Log_Debug("libc", f ,## v)
#include "../../Usermode/Libraries/libc.so_src/strtoi.c"
int ParseInt(const char *string, int *Val)
int pos=0, i;
Uint64 rem;
+ buf[0] = 0;
+ ASSERTR(base >= 2, );
+ ASSERTR(base <= 16, );
+
// Sanity check
if(!buf) return;
- // Sanity Check
- if(base > 16 || base < 2) {
- buf[0] = 0;
- return;
- }
-
// Convert
while(num > base-1) {
num = DivMod64U(num, base, &rem); // Shift `num` and get remainder
ASSERT(rem >= 0);
+ if( rem >= base && base != 16 ) {
+ Debug("rem(%llx) >= base(%x), num=%llx", rem, base, num);
+ }
ASSERT(rem < base);
tmpBuf[pos] = cUCDIGITS[ rem ];
pos++;
GETVAL();
if( isLongLong && val >> 63 ) {
PUTCH('-');
- val = -val;
+ if( val == LLONG_MIN )
+ val = LLONG_MAX;
+ else
+ val = -val;
}
- else if( !isLongLong && val >> 31 ) {
+ else if( !isLongLong && (val >> 31) ) {
PUTCH('-');
- val = -(Sint32)val;
+ val = (~val & 0xFFFFFFFF)+1;
}
itoa(tmpBuf, val, 10, minSize, pad);
goto printString;
case 'C': // Non-Null Terminated Character Array
p = va_arg(args, char*);
- if( !CheckMem(p, minSize) ) continue; // No #PFs please
+ if( !CheckMem(p, minSize) ) {
+ p = "(inval)";
+ goto printString;
+ }
if(!p) goto printString;
while(minSize--) {
- PUTCH(*p);
+ if(*p == '\0') {
+ PUTCH('\\');
+ PUTCH('0');
+ }
+ else if(*p == '\\') {
+ PUTCH('\\');
+ PUTCH('\\');
+ }
+ else {
+ PUTCH(*p);
+ }
p ++;
}
break;