Skip to content
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

Add null terminator to strings returned from fast_serial_read_until #15

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion prawn_do/fast_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uint32_t fast_serial_read(const char * buffer, uint32_t buffer_size){
// Read bytes until terminator reached (blocks until terminator or buffer_size is reached)
uint32_t fast_serial_read_until(char * buffer, uint32_t buffer_size, char until){
uint32_t buffer_idx = 0;
while(buffer_idx < buffer_size){
while(buffer_idx < buffer_size - 1){
while(fast_serial_read_available() > 0){
int32_t next_char = tud_cdc_read_char();

Expand All @@ -51,6 +51,7 @@ uint32_t fast_serial_read_until(char * buffer, uint32_t buffer_size, char until)
}
fast_serial_task();
}
buffer[buffer_idx] = '\0'; // Null terminate string
return buffer_idx;
}

Expand Down
1 change: 1 addition & 0 deletions prawn_do/fast_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static inline uint32_t fast_serial_read_atomic(const char * buffer, uint32_t buf
uint32_t fast_serial_read(const char * buffer, uint32_t buffer_size);

// Read bytes until terminator reached (blocks until terminator or buffer_size is reached)
// Adds null terminator to buffer after read completes (reserving one byte in buffer for this)
uint32_t fast_serial_read_until(char * buffer, uint32_t buffer_size, char until);

// Clear read FIFO (without reading it)
Expand Down