Skip to content

Commit d602d78

Browse files
committed
minor - unify strncpy vs memcpy, silence errors
1 parent dc78211 commit d602d78

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

interface/ceed-jit-tools.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int CeedCheckFilePath(Ceed ceed, const char *source_file_path, bool *is_valid) {
3636

3737
ierr = CeedCalloc(source_file_path_length, &source_file_path_only);
3838
CeedChk(ierr);
39-
strncpy(source_file_path_only, source_file_path, source_file_path_length - 1);
39+
memcpy(source_file_path_only, source_file_path, source_file_path_length - 1);
4040
} else {
4141
source_file_path_only = (char *)source_file_path;
4242
}
@@ -123,7 +123,7 @@ static inline int CeedLoadSourceToInitalizedBuffer(Ceed ceed,
123123
const char *next_e = strchr(first_hash, 'e');
124124
char keyword[8] = "";
125125
if (next_e)
126-
strncpy(keyword, &next_e[-6], 7);
126+
memcpy(keyword, &next_e[-6], 7);
127127
bool is_hash_include = !strcmp(keyword, "include");
128128
// ---- Spaces allowed in '# include <header.h>'
129129
if (next_e)
@@ -134,9 +134,9 @@ static inline int CeedLoadSourceToInitalizedBuffer(Ceed ceed,
134134
long current_size = strlen(*buffer);
135135
long copy_size = first_hash - &temp_buffer[file_offset];
136136
ierr = CeedRealloc(current_size + copy_size + 2, buffer); CeedChk(ierr);
137-
strncpy(&(*buffer)[current_size], "\n", 2);
138-
strncpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size);
139-
strncpy(&(*buffer)[current_size + copy_size], "", 1);
137+
memcpy(&(*buffer)[current_size], "\n", 2);
138+
memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size);
139+
memcpy(&(*buffer)[current_size + copy_size], "", 1);
140140
// -- Load local "header.h"
141141
char *next_quote = strchr(first_hash, '"');
142142
char *next_new_line = strchr(first_hash, '\n');
@@ -149,10 +149,10 @@ static inline int CeedLoadSourceToInitalizedBuffer(Ceed ceed,
149149
long include_file_name_len = strchr(&next_quote[1], '"') - next_quote - 1;
150150
ierr = CeedCalloc(root_length + include_file_name_len + 2,
151151
&include_source_path); CeedChk(ierr);
152-
strncpy(include_source_path, source_file_path, root_length + 1);
153-
strncpy(&include_source_path[root_length + 1], &next_quote[1],
154-
include_file_name_len);
155-
strncpy(&include_source_path[root_length + include_file_name_len + 1], "", 1);
152+
memcpy(include_source_path, source_file_path, root_length + 1);
153+
memcpy(&include_source_path[root_length + 1], &next_quote[1],
154+
include_file_name_len);
155+
memcpy(&include_source_path[root_length + include_file_name_len + 1], "", 1);
156156
// ---- Recursive call to load source to buffer
157157
ierr = CeedLoadSourceToInitalizedBuffer(ceed, include_source_path, buffer);
158158
CeedDebug256(ceed, 2, "JiT Including: %s\n", include_source_path);
@@ -168,9 +168,9 @@ static inline int CeedLoadSourceToInitalizedBuffer(Ceed ceed,
168168
long current_size = strlen(*buffer);
169169
long copy_size = strlen(&temp_buffer[file_offset]);
170170
ierr = CeedRealloc(current_size + copy_size + 2, buffer); CeedChk(ierr);
171-
strncpy(&(*buffer)[current_size], "\n", 2);
172-
strncpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size);
173-
strncpy(&(*buffer)[current_size + copy_size + 1], "", 1);
171+
memcpy(&(*buffer)[current_size], "\n", 2);
172+
memcpy(&(*buffer)[current_size + 1], &temp_buffer[file_offset], copy_size);
173+
memcpy(&(*buffer)[current_size + copy_size + 1], "", 1);
174174

175175
// Cleanup
176176
ierr = CeedFree(&temp_buffer); CeedChk(ierr);
@@ -235,8 +235,8 @@ int CeedPathConcatenate(Ceed ceed, const char *base_file_path,
235235
new_file_path_length = base_length + relative_length + 1;
236236

237237
ierr = CeedCalloc(new_file_path_length, new_file_path); CeedChk(ierr);
238-
strncpy(*new_file_path, base_file_path, base_length);
239-
strncpy(&((*new_file_path)[base_length]), relative_file_path, relative_length);
238+
memcpy(*new_file_path, base_file_path, base_length);
239+
memcpy(&((*new_file_path)[base_length]), relative_file_path, relative_length);
240240

241241
return CEED_ERROR_SUCCESS;
242242
}

interface/ceed-qfunction.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,12 @@ int CeedQFunctionCreateInterior(Ceed ceed, CeedInt vec_length,
616616
const char *kernel_name = strrchr(absolute_path, ':') + 1;
617617
size_t kernel_name_len = strlen(kernel_name);
618618
ierr = CeedCalloc(kernel_name_len + 1, &kernel_name_copy); CeedChk(ierr);
619-
strncpy(kernel_name_copy, kernel_name, kernel_name_len);
619+
memcpy(kernel_name_copy, kernel_name, kernel_name_len);
620620
(*qf)->kernel_name = kernel_name_copy;
621621

622622
size_t source_len = strlen(absolute_path) - kernel_name_len - 1;
623623
ierr = CeedCalloc(source_len + 1, &source_copy); CeedChk(ierr);
624-
strncpy(source_copy, absolute_path, source_len);
624+
memcpy(source_copy, absolute_path, source_len);
625625
(*qf)->source_path = source_copy;
626626

627627
if (!is_absolute_path) {

interface/ceed.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ int CeedStringAllocCopy(const char *source, char **copy) {
302302
int ierr;
303303
size_t len = strlen(source);
304304
ierr = CeedCalloc(len + 1, copy); CeedChk(ierr);
305-
memcpy(*copy, source, len + 1);
305+
memcpy(*copy, source, len);
306306
return CEED_ERROR_SUCCESS;
307307
}
308308

@@ -1025,7 +1025,7 @@ int CeedAddJitSourceRoot(Ceed ceed, const char *jit_source_root) {
10251025
ierr = CeedRealloc(index + 1, &ceed_parent->jit_source_roots); CeedChk(ierr);
10261026
ierr = CeedCalloc(path_length + 1, &ceed_parent->jit_source_roots[index]);
10271027
CeedChk(ierr);
1028-
strncpy(ceed_parent->jit_source_roots[index], jit_source_root, path_length);
1028+
memcpy(ceed_parent->jit_source_roots[index], jit_source_root, path_length);
10291029
ceed_parent->num_jit_source_roots++;
10301030

10311031
return CEED_ERROR_SUCCESS;

0 commit comments

Comments
 (0)