• R/O
  • SSH
  • HTTPS

cstl: Commit


Commit MetaInfo

Revision406 (tree)
Time2010-10-05 21:34:17
Authorkatono

Log Message

sprintfの引数をvoid*からunsigned longに修正。

Change Summary

Incremental Difference

--- branches/try-vfunc/unittest/test/test_LibcImpl.c (revision 405)
+++ branches/try-vfunc/unittest/test/test_LibcImpl.c (revision 406)
@@ -16,52 +16,52 @@
1616 assert(strcmp(buf, sp_buf) == 0);
1717
1818 sprintf(sp_buf, "%s", "piyopiyo");
19- LibcImpl_sprintf(buf, "%s", "piyopiyo", 0, 0, 0);
19+ LibcImpl_sprintf(buf, "%s", (unsigned long)"piyopiyo", 0, 0, 0);
2020 printf("%s\n", buf);
2121 assert(strcmp(buf, sp_buf) == 0);
2222
2323 sprintf(sp_buf, "foo%%bar%s", "hoge");
24- LibcImpl_sprintf(buf, "foo%%bar%s", "hoge", 0, 0, 0);
24+ LibcImpl_sprintf(buf, "foo%%bar%s", (unsigned long)"hoge", 0, 0, 0);
2525 printf("%s\n", buf);
2626 assert(strcmp(buf, sp_buf) == 0);
2727
2828 sprintf(sp_buf, "%d, %d, %d, \"%8d\"", 9999, 0, -1, -1234);
29- LibcImpl_sprintf(buf, "%d, %d, %d, \"%8d\"", (void *)9999, (void*)0, (void*)-1, (void*)-1234);
29+ LibcImpl_sprintf(buf, "%d, %d, %d, \"%8d\"", 9999, 0, -1, -1234);
3030 printf("%s\n", buf);
3131 assert(strcmp(buf, sp_buf) == 0);
3232
3333 sprintf(sp_buf, "%u, %u, %-d, \"%-8d\"", 12345, 0, -123, -111);
34- LibcImpl_sprintf(buf, "%u, %u, %-d, \"%-8d\"", (void *)12345, (void*)0, (void*)-123, (void*)-111);
34+ LibcImpl_sprintf(buf, "%u, %u, %-d, \"%-8d\"", 12345, 0, -123, -111);
3535 printf("%s\n", buf);
3636 assert(strcmp(buf, sp_buf) == 0);
3737
3838 sprintf(sp_buf, "\"%d\", \"%8d\", \"%-8d\", \"%s\"", 123456789, 123456, 789, "abcd");
39- LibcImpl_sprintf(buf, "\"%d\", \"%8d\", \"%-8d\", \"%s\"", (void *)123456789, (void *)123456, (void *)789, "abcd");
39+ LibcImpl_sprintf(buf, "\"%d\", \"%8d\", \"%-8d\", \"%s\"", 123456789, 123456, 789, (unsigned long)"abcd");
4040 printf("%s\n", buf);
4141 assert(strcmp(buf, sp_buf) == 0);
4242
4343 sprintf(sp_buf, "\"%s\", \"%9d\", \"%s\", \"%s\"", "foo", 1234567890, "bar", "abcd");
44- LibcImpl_sprintf(buf, "\"%s\", \"%9d\", \"%s\", \"%s\"", "foo", (void *)1234567890, "bar", "abcd");
44+ LibcImpl_sprintf(buf, "\"%s\", \"%9d\", \"%s\", \"%s\"", (unsigned long)"foo", 1234567890, (unsigned long)"bar", (unsigned long)"abcd");
4545 printf("%s\n", buf);
4646 assert(strcmp(buf, sp_buf) == 0);
4747
4848 sprintf(sp_buf, "%x, \"%8x\", \"%08X\", \"%10d\"", 0x1234, 0x5678, 0xABCD, 12345);
49- LibcImpl_sprintf(buf, "%x, \"%8x\", \"%08X\", \"%10d\"", (void *)0x1234, (void*)0x5678, (void*)0xABCD, (void*)12345);
49+ LibcImpl_sprintf(buf, "%x, \"%8x\", \"%08X\", \"%10d\"", 0x1234, 0x5678, 0xABCD, 12345);
5050 printf("%s\n", buf);
5151 assert(strcmp(buf, sp_buf) == 0);
5252
5353 sprintf(sp_buf, "%x, \"%8x\", \"%-8X\", \"%-10d\"", 0x0, 0x5678, 0xABCD, 12345);
54- LibcImpl_sprintf(buf, "%x, \"%8x\", \"%-8X\", \"%-10d\"", (void *)0x0, (void*)0x5678, (void*)0xABCD, (void*)12345);
54+ LibcImpl_sprintf(buf, "%x, \"%8x\", \"%-8X\", \"%-10d\"", 0x0, 0x5678, 0xABCD, 12345);
5555 printf("%s\n", buf);
5656 assert(strcmp(buf, sp_buf) == 0);
5757
5858 sprintf(sp_buf, "%c, %c, %c, %c", 'a', '#', '\\', '9');
59- LibcImpl_sprintf(buf, "%c, %c, %c, %c", (void *)'a', (void*)'#', (void*)'\\', (void*)'9');
59+ LibcImpl_sprintf(buf, "%c, %c, %c, %c", 'a', '#', '\\', '9');
6060 printf("%s\n", buf);
6161 assert(strcmp(buf, sp_buf) == 0);
6262
63- sprintf(sp_buf, "%p, %p, %p, %p", (void*)0, (void*)buf, (void*)sp_buf, (void*)0);
64- LibcImpl_sprintf(buf, "%p, %p, %p, %p", (void *)0, (void*)buf, (void*)sp_buf, (void*)0);
63+ sprintf(sp_buf, "%p, %p, %p, %p", (void *)0, (void *)buf, (void *)sp_buf, (void *)0);
64+ LibcImpl_sprintf(buf, "%p, %p, %p, %p", 0, (unsigned long)buf, (unsigned long)sp_buf, 0);
6565 printf("%s\n", sp_buf);
6666 printf("%s\n", buf);
6767
--- branches/try-vfunc/unittest/UnitTest.c (revision 405)
+++ branches/try-vfunc/unittest/UnitTest.c (revision 406)
@@ -1,5 +1,6 @@
11 #include <string.h>
22 #include <stdlib.h>
3+#include "UnitTest.h"
34 #include "TestSuite.h"
45 #include "LibcImpl.h"
56
--- branches/try-vfunc/unittest/LibcImpl.h (revision 405)
+++ branches/try-vfunc/unittest/LibcImpl.h (revision 406)
@@ -1,6 +1,7 @@
11 #ifndef LIBCIMPL_H_INCLUDED
22 #define LIBCIMPL_H_INCLUDED
33
4+#include <stddef.h>
45
56 #ifndef NO_STD_PRINTF
67 # include <stdio.h>
@@ -26,12 +27,12 @@
2627 int LibcImpl_printf(const char *format, ...);
2728 # else
2829 # define PRINTF0(f) LibcImpl_printf(f, 0, 0, 0, 0)
29-# define PRINTF1(f, a1) LibcImpl_printf(f, (void *)(a1), 0, 0, 0)
30-# define PRINTF2(f, a1, a2) LibcImpl_printf(f, (void *)(a1), (void *)(a2), 0, 0)
31-# define PRINTF3(f, a1, a2, a3) LibcImpl_printf(f, (void *)(a1), (void *)(a2), (void *)(a3), 0)
32-# define PRINTF4(f, a1, a2, a3, a4) LibcImpl_printf(f, (void *)(a1), (void *)(a2), (void *)(a3), (void *)(a4))
33-int LibcImpl_printf(const char *format, void *arg1, void *arg2, void *arg3, void *arg4);
34-int LibcImpl_sprintf(char *buf, const char *format, void *arg1, void *arg2, void *arg3, void *arg4);
30+# define PRINTF1(f, a1) LibcImpl_printf(f, (unsigned long)(a1), 0, 0, 0)
31+# define PRINTF2(f, a1, a2) LibcImpl_printf(f, (unsigned long)(a1), (unsigned long)(a2), 0, 0)
32+# define PRINTF3(f, a1, a2, a3) LibcImpl_printf(f, (unsigned long)(a1), (unsigned long)(a2), (unsigned long)(a3), 0)
33+# define PRINTF4(f, a1, a2, a3, a4) LibcImpl_printf(f, (unsigned long)(a1), (unsigned long)(a2), (unsigned long)(a3), (unsigned long)(a4))
34+int LibcImpl_printf(const char *format, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4);
35+int LibcImpl_sprintf(char *buf, const char *format, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4);
3536 # endif
3637 #endif
3738
--- branches/try-vfunc/unittest/LibcImpl.c (revision 405)
+++ branches/try-vfunc/unittest/LibcImpl.c (revision 406)
@@ -2,6 +2,8 @@
22
33 #ifdef NO_STD_PRINTF
44
5+#define BUF_SIZE 512
6+
57 char *LibcImpl_fgets(char *s, int size, void *stream)
68 {
79 /* TODO */
@@ -11,6 +13,7 @@
1113 }
1214
1315 #ifdef STD_VSPRINTF
16+#undef stdin
1417 #include <stdarg.h>
1518 #include <stdio.h>
1619
@@ -17,7 +20,7 @@
1720 int LibcImpl_printf(const char *format, ...)
1821 {
1922 /* NOTE: attention to buffer overflow */
20- static char buf[1024];
23+ static char buf[BUF_SIZE];
2124 va_list ap;
2225 va_start(ap, format);
2326 vsprintf(buf, format, ap);
@@ -30,10 +33,10 @@
3033 }
3134
3235 #else
33-int LibcImpl_printf(const char *format, void *arg1, void *arg2, void *arg3, void *arg4)
36+int LibcImpl_printf(const char *format, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4)
3437 {
3538 /* NOTE: attention to buffer overflow */
36- static char buf[1024];
39+ static char buf[BUF_SIZE];
3740 LibcImpl_sprintf(buf, format, arg1, arg2, arg3, arg4);
3841
3942 /* TODO */
@@ -104,7 +107,7 @@
104107 return set_ascii(ascii, tmp, i, width, left_flag, zero_flag);
105108 }
106109
107-static size_t hex2ascii(char *ascii, unsigned int hex, size_t width, int left_flag, int zero_flag, int case_char)
110+static size_t hex2ascii(char *ascii, unsigned long hex, size_t width, int left_flag, int zero_flag, char case_char)
108111 {
109112 size_t i;
110113 char tmp[16];
@@ -121,14 +124,14 @@
121124 return set_ascii(ascii, tmp, i, width, left_flag, zero_flag);
122125 }
123126
124-int LibcImpl_sprintf(char *buf, const char *format, void *arg1, void *arg2, void *arg3, void *arg4)
127+int LibcImpl_sprintf(char *buf, const char *format, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4)
125128 {
126129 size_t i;
127130 const char *p = format;
128- void *arg_list[4];
131+ unsigned long arg_list[4];
129132 size_t arg_idx = 0;
130133 const char *tmp_str;
131- unsigned int tmp_val;
134+ unsigned long tmp_val;
132135 int left_flag;
133136 int zero_flag;
134137 size_t width;
@@ -174,14 +177,14 @@
174177 }
175178 switch (*p) {
176179 case 'c':
177- buf[i++] = (int) arg_list[arg_idx++];
180+ buf[i++] = (char) arg_list[arg_idx++];
178181 p++;
179182 break;
180183 case 'd':
181184 case 'i':
182185 case 'u':
183- tmp_val = (unsigned int) arg_list[arg_idx++];
184- inc = dec2ascii(&buf[i], tmp_val, width, left_flag, zero_flag, (*p == 'u') ? 0 : 1);
186+ tmp_val = arg_list[arg_idx++];
187+ inc = dec2ascii(&buf[i], (unsigned int) tmp_val, width, left_flag, zero_flag, (*p == 'u') ? 0 : 1);
185188 i += inc;
186189 p++;
187190 break;
@@ -192,7 +195,7 @@
192195 width = 8;
193196 case 'x':
194197 case 'X':
195- tmp_val = (unsigned int) arg_list[arg_idx++];
198+ tmp_val = arg_list[arg_idx++];
196199 inc = hex2ascii(&buf[i], tmp_val, width, left_flag, zero_flag, *p);
197200 i += inc;
198201 p++;
Show on old repository browser