2004-07-22 Joerg Wunsch * libc/stdio/fputs_p.c: pgm_read_byte(p++) -> pgm_read_byte(p) ... p++; * libc/stdio/puts_p.c: Ditto. * libc/stdio/vfprintf.c: Ditto. * libc/stdio/vfscanf.c: Ditto. Index: libc/stdio/fputs_p.c =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/fputs_p.c,v retrieving revision 1.3 diff -u -u -r1.3 fputs_p.c --- libc/stdio/fputs_p.c 21 Jul 2004 20:54:50 -0000 1.3 +++ libc/stdio/fputs_p.c 21 Jul 2004 22:09:33 -0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2002, Joerg Wunsch +/* Copyright (c) 2002,2004 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without @@ -43,9 +43,15 @@ if ((stream->flags & __SWR) == 0) return EOF; - while ((c = pgm_read_byte(str++)) != '\0') + /* + * Do not use str++ in the next line. pgm_read_byte() is a + * macro, so it could evaluate its argument more than once. + */ + while ((c = pgm_read_byte(str)) != '\0') { if (stream->put(c) != 0) rv = EOF; + str++; + } return rv; } Index: libc/stdio/puts_p.c =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/puts_p.c,v retrieving revision 1.3 diff -u -u -r1.3 puts_p.c --- libc/stdio/puts_p.c 21 Jul 2004 20:54:50 -0000 1.3 +++ libc/stdio/puts_p.c 21 Jul 2004 22:09:33 -0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2002, Joerg Wunsch +/* Copyright (c) 2002,2004 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without @@ -43,9 +43,15 @@ if ((stdout->flags & __SWR) == 0) return EOF; - while ((c = pgm_read_byte(str++)) != '\0') + /* + * Do not use str++ in the next line. pgm_read_byte() is a + * macro, so it could evaluate its argument more than once. + */ + while ((c = pgm_read_byte(str)) != '\0') { if (stdout->put(c) != 0) rv = EOF; + str++; + } if (stdout->put('\n') != 0) rv = EOF; Index: libc/stdio/vfprintf.c =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/vfprintf.c,v retrieving revision 1.8 diff -u -u -r1.8 vfprintf.c --- libc/stdio/vfprintf.c 21 Jul 2004 20:54:50 -0000 1.8 +++ libc/stdio/vfprintf.c 21 Jul 2004 22:09:34 -0000 @@ -1,5 +1,5 @@ /* Copyright (c) 2002, Alexander Popov (address@hidden) - Copyright (c) 2002, Joerg Wunsch + Copyright (c) 2002,2004 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without @@ -138,7 +138,14 @@ if ((stream->flags & __SWR) == 0) return EOF; - while ((c = ((stream->flags & __SPGM)? pgm_read_byte(fmt++): *fmt++))) { + /* + * Do not use fmt++ in the next line. pgm_read_byte() is a + * macro, so it could evaluate its argument more than once. + */ + while ((c = ((stream->flags & __SPGM)? pgm_read_byte(fmt): *fmt))) { + + fmt++; + if (flags & FLHASPERCENT) { if (c >= '0' && c <= '9') { #if PRINTF_LEVEL > PRINTF_MIN Index: libc/stdio/vfscanf.c =================================================================== RCS file: /cvsroot/avr-libc/avr-libc/libc/stdio/vfscanf.c,v retrieving revision 1.5 diff -u -u -r1.5 vfscanf.c --- libc/stdio/vfscanf.c 21 Jul 2004 20:54:50 -0000 1.5 +++ libc/stdio/vfscanf.c 21 Jul 2004 22:09:34 -0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2002, Joerg Wunsch +/* Copyright (c) 2002,2004 Joerg Wunsch All rights reserved. Redistribution and use in source and binary forms, with or without @@ -120,7 +120,14 @@ if ((stream->flags & __SRD) == 0) return EOF; - while ((c = ((stream->flags & __SPGM)? pgm_read_byte(fmt++): *fmt++))) { + /* + * Do not use fmt++ in the next line. pgm_read_byte() is a + * macro, so it could evaluate its argument more than once. + */ + while ((c = ((stream->flags & __SPGM)? pgm_read_byte(fmt): *fmt))) { + + fmt++; + #if SCANF_LEVEL >= SCANF_FLT if (flags & FLBRACKET) { if (c == '^' && i == 0 && !(flags & FLNEGATE)) {