[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] [PATCH] printf: %s arguments with precision
From: |
Christopher Hoover |
Subject: |
[avr-libc-dev] [PATCH] printf: %s arguments with precision |
Date: |
Sun, 1 Feb 2004 12:51:27 -0800 (PST) |
printf and friends improperly handle non-null termnated strings when a
%s argument has a precision.
"improperly handle" in this case is often a fatal error as the
function is doing (effectively) strlen(). :-(
here's a patch.
-ch
ch(a)murgatroid.com
--- avr-libc-1.0.2/libc/stdio/vfprintf.c 2003-01-02 08:27:43.000000000
-0800
+++ avr-libc-1.0.2.ch/libc/stdio/vfprintf.c 2004-02-01 12:36:41.000000000
-0800
@@ -332,12 +332,14 @@ vfprintf(FILE *stream, const char *fmt,
goto nextitem;
case 's':
a.pc = va_arg(ap, char *);
- for (base = 0; a.pc[base]; base++)
- ; /* calc length of string */
#if PRINTF_LEVEL > PRINTF_MIN
- if ((flags & FLPREC) && prec < base)
- base = prec;
+ if (flags & FLPREC)
+ base = strnlen(a.pc, prec);
+ else
+ base = strlen(a.pc);
width -= base;
+#else
+ base = strlen(a.pc);
#endif
goto nextitem;
case 'd':
- [avr-libc-dev] [PATCH] printf: %s arguments with precision,
Christopher Hoover <=
- Re: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Joerg Wunsch, 2004/02/02
- RE: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Christopher Hoover, 2004/02/02
- Re: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Joerg Wunsch, 2004/02/12
- Re: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Joerg Wunsch, 2004/02/12
- Re: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Theodore A. Roth, 2004/02/12
- Re: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Joerg Wunsch, 2004/02/15
Re: [avr-libc-dev] [PATCH] printf: %s arguments with precision, Joerg Wunsch, 2004/02/02