Skip to content

Commit 679667f

Browse files
committed
Redo 'Fix pulling string samples with embedded NULL bytes' b3c5886
1 parent d82e8b6 commit 679667f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lsl_inlet_c.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ LIBLSL_C_API double lsl_pull_sample_str(
116116
if (ec) *ec = lsl_internal_error;
117117
return 0.0;
118118
}
119-
strcpy(buffer[k], tmp[k].c_str());
119+
memcpy(buffer[k], tmp[k].c_str(), tmp[k].size());
120+
buffer[k][tmp[k].size()] = '\0';
120121
}
121122
return result;
122123
} LSL_STORE_EXCEPTION_IN(ec)
@@ -218,7 +219,8 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_str(lsl_inlet in, char **data_buffer,
218219
if (ec) *ec = lsl_internal_error;
219220
return 0;
220221
}
221-
strcpy(data_buffer[k], tmp[k].c_str());
222+
memcpy(data_buffer[k], tmp[k].c_str(), tmp[k].size());
223+
data_buffer[k][tmp[k].size()] = '\0';
222224
}
223225
return result;
224226
} else
@@ -246,7 +248,8 @@ LIBLSL_C_API unsigned long lsl_pull_chunk_buf(lsl_inlet in, char **data_buffer,
246248
return 0;
247249
}
248250
lengths_buffer[k] = (uint32_t)tmp[k].size();
249-
strcpy(data_buffer[k], tmp[k].c_str());
251+
memcpy(data_buffer[k], tmp[k].c_str(), tmp[k].size());
252+
data_buffer[k][tmp[k].size()] = '\0';
250253
}
251254
return result;
252255
} else

0 commit comments

Comments
 (0)