Hello tianye,

On 12/20/22 03:59, tia...@sugon.com wrote:
Hi:
I have a testcode, it will lead to uart print space forever.

Demo code like this:
Init()
{
create a task;
start this task;
*printf("%*\n");* while(1) { sleep() } } This code lead to uart print space forever('SPACE' ascii is 0x20): 'SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE''SPACE'......

"%*\n" is an illegal or incorrect "conversion specification" because is misses an "conversion specifier" (e.g. an "d", "s" or "x" before the "\n"). Whether the behavior is a bug depends on the specification of the behavior of `printf()` in such a case. I am not aware of any specification of what should happen when the "conversion specification" is malformed.

I tried with gcc on an ordinary Linux and it printed (to my surprise):

%107348472

The print out of spaces cannot be excused with the presents of a field with specifier "*" because without knowing the length of the content of the field - due to the missing conversion specifier - the software cannot calculate how may spaces to print out.

Anyway, your `printf()` should trigger this compiler warning:

../../../testsuites/samples/hello/init.c:44:14: warning: unknown conversion type character '\x0a' in format [-Wformat=]
   44 |   printf( "%*\n" );
      |              ^~

Since the issue appears to be triggered in newlib code, I believe changing RTEMS code wont help in any case. Yet, again it is dubious to me whether this is a bug in the first place.

Greetings
Frank

--
embedded brains GmbH
Herr Frank KÜHNDEL
Dornierstr. 4
82178 Puchheim
Germany
email: frank.kuehn...@embedded-brains.de
phone:  +49-89-18 94 741 - 23
mobile: +49-176-15 22 06 - 11
fax:    +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

_______________________________________________
users mailing list
users@rtems.org
http://lists.rtems.org/mailman/listinfo/users

Reply via email to