Skip to content

Fix overflow of write_buffer #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ void process(const pio_spi_inst_t *spi, int command) {

uint32_t wlen = getu24();
uint32_t rlen = getu24();
uint32_t chunk;

cs_select(PIN_CS);
fread(write_buffer, 1, wlen, stdin);
pio_spi_write8_blocking(spi, write_buffer, wlen);

for(uint32_t i = 0; i < wlen; i += chunk) {
chunk = MIN(wlen - i, sizeof(write_buffer));
fread(write_buffer, 1, wlen, stdin);
pio_spi_write8_blocking(spi, write_buffer, wlen);
}

putchar(S_ACK);
uint32_t chunk;
char buf[128];

for(uint32_t i = 0; i < rlen; i += chunk) {
Expand Down