Sun Jan 23 02:08:24 2011 UTC ()
fix a failure in the sign extension consideration.


(nisimura)
diff -r1.2 -r1.3 src/sys/arch/sandpoint/stand/altboot/printf.c

cvs diff -r1.2 -r1.3 src/sys/arch/sandpoint/stand/altboot/Attic/printf.c (expand / switch to unified diff)

--- src/sys/arch/sandpoint/stand/altboot/Attic/printf.c 2011/01/23 01:32:08 1.2
+++ src/sys/arch/sandpoint/stand/altboot/Attic/printf.c 2011/01/23 02:08:24 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: printf.c,v 1.2 2011/01/23 01:32:08 nisimura Exp $ */ 1/* $NetBSD: printf.c,v 1.3 2011/01/23 02:08:24 nisimura Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tohru Nishimura. 8 * by Tohru Nishimura.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -86,27 +86,28 @@ snprintf(char *buf, size_t size, const c @@ -86,27 +86,28 @@ snprintf(char *buf, size_t size, const c
86 _doprnt(sputchar, fmt, ap); 86 _doprnt(sputchar, fmt, ap);
87 *sbuf = '\0'; 87 *sbuf = '\0';
88 return (sbuf - buf); 88 return (sbuf - buf);
89} 89}
90 90
91static int 91static int
92_doprnt(void (*func)(int), const char *fmt, va_list ap) 92_doprnt(void (*func)(int), const char *fmt, va_list ap)
93{ 93{
94 int i, outcnt; 94 int i, outcnt;
95 char buf[23], *str; /* requires 23 digits in octal at most */ 95 char buf[23], *str; /* requires 23 digits in octal at most */
96 int length, fmax, fmin, leading; 96 int length, fmax, fmin, leading;
97 int leftjust, llflag; 97 int leftjust, llflag;
98 char fill, sign; 98 char fill, sign;
99 long long v; 99 long long d;
 100 unsigned long long v;
100 101
101 outcnt = 0; 102 outcnt = 0;
102 while ((i = *fmt++) != '\0') { 103 while ((i = *fmt++) != '\0') {
103 if (i != '%') { 104 if (i != '%') {
104 (*func)(i); 105 (*func)(i);
105 outcnt += 1; 106 outcnt += 1;
106 continue; 107 continue;
107 } 108 }
108 if (*fmt == '%') { 109 if (*fmt == '%') {
109 (*func)(*fmt++); 110 (*func)(*fmt++);
110 outcnt += 1; 111 outcnt += 1;
111 continue; 112 continue;
112 } 113 }
@@ -150,59 +151,59 @@ _doprnt(void (*func)(int), const char *f @@ -150,59 +151,59 @@ _doprnt(void (*func)(int), const char *f
150 str[0] = va_arg(ap, int); 151 str[0] = va_arg(ap, int);
151 str[1] = '\0'; 152 str[1] = '\0';
152 fmax = 0; 153 fmax = 0;
153 fill = ' '; 154 fill = ' ';
154 break; 155 break;
155 156
156 case 's': 157 case 's':
157 str = va_arg(ap, char *); 158 str = va_arg(ap, char *);
158 fill = ' '; 159 fill = ' ';
159 break; 160 break;
160 161
161 case 'd': 162 case 'd':
162 if (llflag) 163 if (llflag)
163 v = va_arg(ap, long long); 164 d = va_arg(ap, long long);
164 else 165 else
165 v = va_arg(ap, int); 166 d = va_arg(ap, int);
166 if (v < 0) { 167 if (d < 0) {
167 sign = '-' ; v = -v; 168 sign = '-' ; d = -d;
168 } 169 }
169 mkdigit((unsigned long long)v, 10, str); 170 mkdigit((unsigned long long)d, 10, str);
170 break; 171 break;
171 172
172 case 'u': 173 case 'u':
173 if (llflag) 174 if (llflag)
174 v = va_arg(ap, long long); 175 v = va_arg(ap, unsigned long long);
175 else 176 else
176 v = va_arg(ap, int); 177 v = va_arg(ap, unsigned int);
177 mkdigit((unsigned long long)v, 10, str); 178 mkdigit(v, 10, str);
178 break; 179 break;
179 180
180 case 'o': 181 case 'o':
181 if (llflag) 182 if (llflag)
182 v = va_arg(ap, long long); 183 v = va_arg(ap, unsigned long long);
183 else 184 else
184 v = va_arg(ap, int); 185 v = va_arg(ap, unsigned int);
185 mkdigit((unsigned long long)v, 8, str); 186 mkdigit(v, 8, str);
186 fmax = 0; 187 fmax = 0;
187 break; 188 break;
188 189
189 case 'X': 190 case 'X':
190 case 'x': 191 case 'x':
191 if (llflag) 192 if (llflag)
192 v = va_arg(ap, long long); 193 v = va_arg(ap, unsigned long long);
193 else 194 else
194 v = va_arg(ap, int); 195 v = va_arg(ap, unsigned int);
195 mkdigit((unsigned long long)v, 16, str); 196 mkdigit(v, 16, str);
196 fmax = 0; 197 fmax = 0;
197 break; 198 break;
198 199
199 case 'p': 200 case 'p':
200 mkdigit(va_arg(ap, unsigned int), 16, str); 201 mkdigit(va_arg(ap, unsigned int), 16, str);
201 fill = '0'; 202 fill = '0';
202 fmin = 8; 203 fmin = 8;
203 fmax = 0; 204 fmax = 0;
204 (*func)('0'); (*func)('x'); 205 (*func)('0'); (*func)('x');
205 outcnt += 2; 206 outcnt += 2;
206 break; 207 break;
207 208
208 default: 209 default: