tests/pipe: cleanup application#12792
Conversation
| while (read_total < BYTES_TOTAL) { | ||
| char buf[4]; | ||
| unsigned read = pipe_read(&pipes[0], buf, sizeof (buf)); | ||
| buf[read] = 0; |
There was a problem hiding this comment.
Potential buffer overflow by one byte. (pipe_read() reads up to sizeof(buf) bytes. I suggest to increase the buffer by one byte and read only sizeof(buf) - 1 bytes. Same below.
There was a problem hiding this comment.
Makes sense, thanks!
|
As a side note, the problem in |
|
It could be added to avr-libc. But that would be pretty long term till it reaches users. To me it actually makes sense that only a subset of printf formatters are available on low end systems. |
Thanks for your prompt reply @maribu. Then let's go with the strategy of this PR and I'll also open another PR for |
The string formatter initially used doesn't seem to be supported by the AVR toolchain. Correctly closing the buffer with a null byte and using plain %s formatter works in all cases
f1df0e3 to
a081fb6
Compare
Contribution description
This PR is cleaning up the
tests/pipeapplication to make it also work with AVR. I have to admit that I didn't know the printf syntax (%.*s) to print a string given a length and a buffer.Apparently this doesn't work with the AVR toolchain so the fix is just to close the string with a null byte explicitly and use
%sformatter in the print.Testing procedure
Issues/PRs references
Tick one item in #12651