git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Modules/EHCI - Untested interrupt support
[tpg/acess2.git]
/
KernelLand
/
Kernel
/
libc.c
diff --git
a/KernelLand/Kernel/libc.c
b/KernelLand/Kernel/libc.c
index
b0c083b
..
d42e524
100644
(file)
--- a/
KernelLand/Kernel/libc.c
+++ b/
KernelLand/Kernel/libc.c
@@
-156,19
+156,20
@@
void itoa(char *buf, Uint64 num, int base, int minLength, char pad)
int pos=0, i;
Uint64 rem;
int pos=0, i;
Uint64 rem;
+ buf[0] = 0;
+ ASSERTR(base >= 2, );
+ ASSERTR(base <= 16, );
+
// Sanity check
if(!buf) return;
// 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);
// 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++;
ASSERT(rem < base);
tmpBuf[pos] = cUCDIGITS[ rem ];
pos++;
@@
-187,8
+188,8
@@
void itoa(char *buf, Uint64 num, int base, int minLength, char pad)
* \brief Append a character the the vsnprintf output
*/
#define PUTCH(ch) do { \
* \brief Append a character the the vsnprintf output
*/
#define PUTCH(ch) do { \
- if(pos < __maxlen) { \
-
if(__s)
__s[pos] = ch; \
+ if(pos < __maxlen
&& __s
) { \
+ __s[pos] = ch; \
} else { \
(void)ch;\
} \
} else { \
(void)ch;\
} \
@@
-201,7
+202,7
@@
void itoa(char *buf, Uint64 num, int base, int minLength, char pad)
/**
* \brief VArg String Number Print Formatted
*/
/**
* \brief VArg String Number Print Formatted
*/
-int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
+int vsnprintf(char *__s,
const
size_t __maxlen, const char *__format, va_list args)
{
char c, pad = ' ';
int minSize = 0, precision = -1, len;
{
char c, pad = ' ';
int minSize = 0, precision = -1, len;
@@
-316,11
+317,14
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
GETVAL();
if( isLongLong && val >> 63 ) {
PUTCH('-');
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('-');
PUTCH('-');
- val =
-(Sint32)val
;
+ val =
(~val & 0xFFFFFFFF)+1
;
}
itoa(tmpBuf, val, 10, minSize, pad);
goto printString;
}
itoa(tmpBuf, val, 10, minSize, pad);
goto printString;
@@
-390,7
+394,13
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
if( !CheckMem(p, minSize) ) continue; // No #PFs please
if(!p) goto printString;
while(minSize--) {
if( !CheckMem(p, minSize) ) continue; // No #PFs please
if(!p) goto printString;
while(minSize--) {
- PUTCH(*p);
+ if(*p == '\0') {
+ PUTCH('\\');
+ PUTCH('0');
+ }
+ else {
+ PUTCH(*p);
+ }
p ++;
}
break;
p ++;
}
break;
@@
-404,7
+414,7
@@
int vsnprintf(char *__s, size_t __maxlen, const char *__format, va_list args)
}
}
}
}
- if(__s && pos
!=
__maxlen)
+ if(__s && pos
<
__maxlen)
__s[pos] = '\0';
return pos;
__s[pos] = '\0';
return pos;
UCC
git Repository :: git.ucc.asn.au