Skip to content

Commit

Permalink
Redo 'Fix pulling string samples with embedded NULL bytes' b3c5886
Browse files Browse the repository at this point in the history
  • Loading branch information
cboulay committed May 11, 2021
1 parent d82e8b6 commit 679667f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lsl_inlet_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ LIBLSL_C_API double lsl_pull_sample_str(
if (ec) *ec = lsl_internal_error;
return 0.0;
}
strcpy(buffer[k], tmp[k].c_str());
memcpy(buffer[k], tmp[k].c_str(), tmp[k].size());
buffer[k][tmp[k].size()] = '\0';
}
return result;
} LSL_STORE_EXCEPTION_IN(ec)
Expand Down Expand Up @@ -218,7 +219,8 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_str(lsl_inlet in, char **data_buffer,
if (ec) *ec = lsl_internal_error;
return 0;
}
strcpy(data_buffer[k], tmp[k].c_str());
memcpy(data_buffer[k], tmp[k].c_str(), tmp[k].size());
data_buffer[k][tmp[k].size()] = '\0';
}
return result;
} else
Expand Down Expand Up @@ -246,7 +248,8 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_buf(lsl_inlet in, char **data_buffer,
return 0;
}
lengths_buffer[k] = (uint32_t)tmp[k].size();
strcpy(data_buffer[k], tmp[k].c_str());
memcpy(data_buffer[k], tmp[k].c_str(), tmp[k].size());
data_buffer[k][tmp[k].size()] = '\0';
}
return result;
} else
Expand Down

0 comments on commit 679667f

Please sign in to comment.