That happens in the next line.. idx can't reach a value that would cause an overflow.
Yes you are right, I was thinking wrong.
And actually it's smart to "append" the null char after every receive.
I don't know if there is any use in this case?
The only thing I can think of is when having some
receive timeout functionality.
And I don't think the > sign is needed
as the receive is very controlled
and the
idx is only incremented once in the loop
it would have been sufficient to only use ==
Code:
(idx == sizeof(buf) -1) )
Nope, it would still crash if a line is longer, by accident.
That's not a good coding style.
That is not true as the original code was taking that into account(unless MAX_INPUT is bigger than 1000)
"crash" is a strong word in this case.
I had a long description here to describe all the problems
but then it hit me.
the post contains no notice about
MAX_INPUT
and the code contains no trace of it.
so I can not post that until we know what value that is set to
the following is a little overkill for this application (specially at this state)
char buffer[1000]; //buffer for serial data receive from PC
simple and last
"Forum Rule: Always post complete source code & details to reproduce any issue!"