mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-03-04 06:10:23 +01:00
Replaced some strnlen by memcpy
This commit is contained in:
parent
770b136c59
commit
a5d39acc92
@ -840,8 +840,10 @@ trexio_string_of_error (const trexio_exit_code error)
|
||||
void
|
||||
trexio_string_of_error_f (const trexio_exit_code error, char result[<<MAX_STRING_LENGTH()>>])
|
||||
{
|
||||
strncpy(result, trexio_string_of_error(error), <<MAX_STRING_LENGTH()>>);
|
||||
result[<<MAX_STRING_LENGTH()>>-1] = '\0';
|
||||
const char* pSrc = trexio_string_of_error(error);
|
||||
size_t sizeCp = strnlen(pSrc, <<MAX_STRING_LENGTH()>>);
|
||||
memcpy(result, pSrc, sizeCp);
|
||||
result[sizeCp] = '\0';
|
||||
}
|
||||
#+end_src
|
||||
|
||||
@ -1291,9 +1293,11 @@ trexio_open(const char* file_name, const char mode,
|
||||
|
||||
/* Data for the parent type */
|
||||
|
||||
strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH);
|
||||
result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] = '\0';
|
||||
if (result->file_name[TREXIO_MAX_FILENAME_LENGTH-2] != '\0') {
|
||||
// See https://stackoverflow.com/a/50198398/4151327
|
||||
size_t lenSrc = strnlen(file_name, TREXIO_MAX_FILENAME_LENGTH-1);
|
||||
if (lenSrc < TREXIO_MAX_FILENAME_LENGTH) {
|
||||
memcpy(result->file_name, file_name, lenSrc+1);
|
||||
} else {
|
||||
if (rc_open != NULL) *rc_open = TREXIO_INVALID_ARG_1;
|
||||
free(result);
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user