Topic : STM8 gets() error

Forum : ST7/STM8

Original Post
Post Information Post
December 18, 2012 - 9:43pm
Guest

gets() must add null character at the end of string
here is asm code of gets

0x81b8 <?gets>              0x89            PUSHW X                   PUSHW X 
0x81b9 <?gets+1>            0x89            PUSHW X                   PUSHW X 
0x81ba <?gets+2>            0xCD8178        CALL  0x8178              CALL  getchar 
0x81bd <?gets+5>            0x85            POPW  X                   POPW  X 
0x81be <?gets+6>            0xA10A          CP    A,#0x0a             CP    A,#0x0a 
0x81c0 <?gets+8>            0x2704          JREQ  0x81c6              JREQ  0x81c6 
0x81c2 <?gets+10>           0xF7            LD    (X),A               LD    (X),A 
0x81c3 <?gets+11>           0x5C            INCW  X                   INCW  X 
0x81c4 <?gets+12>           0x20F3          JRT   0x81b9              JRT   0x81b9 
0x81c6 <?gets+14>           0x85            POPW  X                   POPW  X 
0x81c7 <?gets+15>           0x81            RET                       RET 

as far as I see, gets() does not add the string terminator

STM8S105 mcu, small model,
RCSTM8 COMPILER V2.48.12.338 - Lite (32 Kb code limited)

Replies
Post Information Post
+1
0
-1
December 19, 2012 - 12:26pm
Raisonance Support Team

Indeed!

Fixed. Fix will be available in the next release.

Stéphane

+1
0
-1
December 19, 2012 - 4:51pm
Guest

As far as you're touching the code, I have two more feature requests:
- accept 0xd as end-of line
- make the gets() version with length control, (fgets with fake file?).

Is {s}scanf() going to be implemented?

+1
0
-1
December 20, 2012 - 2:47pm
Raisonance Support Team

gets accepts now \r as end-of-line character.

In the next release, RCSTM8 library will implement C11 char* gets_s(char* s, int n)

{s}scanf() is in the todo list, but I cannot promise it will be available.

Stéphane

+1
0
-1
December 20, 2012 - 8:09pm
Guest

Thanks, Stephane!

+1
0
-1
December 21, 2012 - 12:31am
Raisonance Support Team

Wow, sscanf! Stéphane you are in good mood for doomsday...