Skip to content

Commit e23746a

Browse files
David Laightgregkh
authored andcommitted
tools/nolibc/printf: Change variables 'c' to 'ch' and 'tmpbuf[]' to 'outbuf[]'
[ Upstream commit f675ae2 ] Changing 'c' makes the code slightly easier to read because the variable stands out from the single character literals (especially 'c'). Change tmpbuf[] to outbuf[] because 'out' points into it. The following patches pretty much rewrite the function so the churn is limited. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260223101735.2922-7-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Stable-dep-of: 4045e7b ("tools/nolibc/printf: Move snprintf length check to callback") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8e7f0e3 commit e23746a

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

tools/include/nolibc/stdio.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,34 +301,34 @@ typedef int (*__nolibc_printf_cb)(intptr_t state, const char *buf, size_t size);
301301
static __attribute__((unused, format(printf, 4, 0)))
302302
int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char *fmt, va_list args)
303303
{
304-
char escape, lpref, c;
304+
char escape, lpref, ch;
305305
unsigned long long v;
306306
unsigned int written, width;
307307
size_t len, ofs, w;
308-
char tmpbuf[21];
308+
char outbuf[21];
309309
const char *outstr;
310310

311311
written = ofs = escape = lpref = 0;
312312
while (1) {
313-
c = fmt[ofs++];
313+
ch = fmt[ofs++];
314314
width = 0;
315315

316316
if (escape) {
317317
/* we're in an escape sequence, ofs == 1 */
318318
escape = 0;
319319

320320
/* width */
321-
while (c >= '0' && c <= '9') {
321+
while (ch >= '0' && ch <= '9') {
322322
width *= 10;
323-
width += c - '0';
323+
width += ch - '0';
324324

325-
c = fmt[ofs++];
325+
ch = fmt[ofs++];
326326
}
327327

328-
if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') {
329-
char *out = tmpbuf;
328+
if (ch == 'c' || ch == 'd' || ch == 'u' || ch == 'x' || ch == 'p') {
329+
char *out = outbuf;
330330

331-
if (c == 'p')
331+
if (ch == 'p')
332332
v = va_arg(args, unsigned long);
333333
else if (lpref) {
334334
if (lpref > 1)
@@ -338,15 +338,15 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
338338
} else
339339
v = va_arg(args, unsigned int);
340340

341-
if (c == 'd') {
341+
if (ch == 'd') {
342342
/* sign-extend the value */
343343
if (lpref == 0)
344344
v = (long long)(int)v;
345345
else if (lpref == 1)
346346
v = (long long)(long)v;
347347
}
348348

349-
switch (c) {
349+
switch (ch) {
350350
case 'c':
351351
out[0] = v;
352352
out[1] = 0;
@@ -365,30 +365,30 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
365365
u64toh_r(v, out);
366366
break;
367367
}
368-
outstr = tmpbuf;
368+
outstr = outbuf;
369369
}
370-
else if (c == 's') {
370+
else if (ch == 's') {
371371
outstr = va_arg(args, char *);
372372
if (!outstr)
373373
outstr="(null)";
374374
}
375-
else if (c == 'm') {
375+
else if (ch == 'm') {
376376
#ifdef NOLIBC_IGNORE_ERRNO
377377
outstr = "unknown error";
378378
#else
379379
outstr = strerror(errno);
380380
#endif /* NOLIBC_IGNORE_ERRNO */
381381
}
382-
else if (c == '%') {
382+
else if (ch == '%') {
383383
/* queue it verbatim */
384384
continue;
385385
}
386386
else {
387387
/* modifiers or final 0 */
388-
if (c == 'l') {
388+
if (ch == 'l') {
389389
/* long format prefix, maintain the escape */
390390
lpref++;
391-
} else if (c == 'j') {
391+
} else if (ch == 'j') {
392392
lpref = 2;
393393
}
394394
escape = 1;
@@ -399,7 +399,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
399399
}
400400

401401
/* not an escape sequence */
402-
if (c == 0 || c == '%') {
402+
if (ch == 0 || ch == '%') {
403403
/* flush pending data on escape or end */
404404
escape = 1;
405405
lpref = 0;
@@ -420,7 +420,7 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
420420

421421
written += len;
422422
do_escape:
423-
if (c == 0)
423+
if (ch == 0)
424424
break;
425425
fmt += ofs;
426426
ofs = 0;

0 commit comments

Comments
 (0)