Changes to use stdarg rather than assume that arguments are on the stack
and in the correct order. Tested on i386 and powerpc.
Modified: trunk/reactos/boot/freeldr/freeldr/rtl/print.c
Modified: trunk/reactos/boot/freeldr/freeldr/rtl/stdlib.c
_____
Modified: trunk/reactos/boot/freeldr/freeldr/rtl/print.c
--- trunk/reactos/boot/freeldr/freeldr/rtl/print.c 2005-04-01
00:04:15 UTC (rev 14396)
+++ trunk/reactos/boot/freeldr/freeldr/rtl/print.c 2005-04-01
00:15:04 UTC (rev 14397)
@@ -20,6 +20,7 @@
#include <freeldr.h>
#include <machine.h>
#include <rtl.h>
+#include <stdarg.h>
/*
* print() - prints unformatted text to stdout
@@ -38,12 +39,11 @@
*/
void printf(char *format, ... )
{
- int *dataptr = (int *)(void *)&format;
+ va_list ap;
+ va_start(ap,format);
char c, *ptr, str[16];
int ll;
- dataptr++;
-
while ((c = *(format++)))
{
if (c != '%')
@@ -66,11 +66,11 @@
case 'd': case 'u': case 'x':
if (ll)
{
- *convert_i64_to_ascii(str, c,
*((unsigned long long *) dataptr++)) = 0;
+ *convert_i64_to_ascii(str, c,
va_arg(ap, unsigned long long)) = 0;
}
else
{
- *convert_to_ascii(str, c,
*((unsigned long *) dataptr++)) = 0;
+ *convert_to_ascii(str, c,
va_arg(ap, unsigned long)) = 0;
}
ptr = str;
@@ -81,10 +81,10 @@
}
break;
- case 'c': MachConsPutChar((*(dataptr++))&0xff);
break;
+ case 'c':
MachConsPutChar((va_arg(ap,int))&0xff); break;
case 's':
- ptr = (char *)(*(dataptr++));
+ ptr = va_arg(ap,char *);
while ((c = *(ptr++)))
{
@@ -100,16 +100,18 @@
}
}
}
+
+ va_end(ap);
}
void sprintf(char *buffer, char *format, ... )
{
- int *dataptr = (int *)(void *)&format;
+ va_list ap;
char c, *ptr, str[16];
char *p = buffer;
int ll;
- dataptr++;
+ va_start(ap,format);
while ((c = *(format++)))
{
@@ -134,11 +136,11 @@
case 'd': case 'u': case 'x':
if (ll)
{
- *convert_i64_to_ascii(str, c,
*((unsigned long long*) dataptr++)) = 0;
+ *convert_i64_to_ascii(str, c,
va_arg(ap, unsigned long long)) = 0;
}
else
{
- *convert_to_ascii(str, c,
*((unsigned long *) dataptr++)) = 0;
+ *convert_to_ascii(str, c,
va_arg(ap, unsigned long)) = 0;
}
ptr = str;
@@ -151,12 +153,12 @@
break;
case 'c':
- *p = (*(dataptr++))&0xff;
+ *p = va_arg(ap,int)&0xff;
p++;
break;
case 's':
- ptr = (char *)(*(dataptr++));
+ ptr = va_arg(ap,char *);
while ((c = *(ptr++)))
{
@@ -174,5 +176,6 @@
}
}
}
+ va_end(ap);
*p=0;
}
_____
Modified: trunk/reactos/boot/freeldr/freeldr/rtl/stdlib.c
--- trunk/reactos/boot/freeldr/freeldr/rtl/stdlib.c 2005-04-01
00:04:15 UTC (rev 14396)
+++ trunk/reactos/boot/freeldr/freeldr/rtl/stdlib.c 2005-04-01
00:15:04 UTC (rev 14397)
@@ -17,16 +17,15 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
/*
* convert_to_ascii() - converts a number to it's ascii equivalent
* from:
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1996 Erich Boleyn <erich(a)uruk.org>
*/
-char *convert_to_ascii(char *buf, int c, ...)
+char *convert_to_ascii(char *buf, int c, int num)
{
- unsigned long num = *((&c) + 1), mult = 10;
+ unsigned long mult = 10;
char *ptr = buf;
if (c == 'x')
@@ -63,9 +62,8 @@
return ptr;
}
-char *convert_i64_to_ascii(char *buf, int c, ...)
+char *convert_i64_to_ascii(char *buf, int c, unsigned long long num)
{
- unsigned long long num = *(long long*)((&c) + 1);
int mult = 10;
char *ptr = buf;