Use memcpy instead of strncpy in cases where we want to use only parts of strings. GCC 8.1 and higher warns about using strncpy when it detects possible truncations already at compile time.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-05-25 13:26:08 +02:00
parent 96320db367
commit cc8b44d85f
3 changed files with 4 additions and 4 deletions

2
api.c
View File

@@ -972,7 +972,7 @@ void getVersion(const int *sock)
// Extract first 7 characters of the hash
char hash[8];
strncpy(hash, commit, 7); hash[7] = 0;
memcpy(hash, commit, 7); hash[7] = 0;
if(strlen(tag) > 1) {
if(istelnet[*sock])

2
args.c
View File

@@ -62,7 +62,7 @@ void parse_args(int argc, char* argv[])
const char * commit = GIT_HASH;
char hash[8];
// Extract first 7 characters of the hash
strncpy(hash, commit, 7); hash[7] = 0;
memcpy(hash, commit, 7); hash[7] = 0;
printf("vDev-%s\n", hash);
}
exit(EXIT_SUCCESS);

View File

@@ -86,8 +86,8 @@ size_t addstr(const char *str)
counters->strings_MAX = shm_strings.size;
// Copy the C string pointed by str into the shared string buffer
strncpy(&((char*)shm_strings.ptr)[shmSettings->next_str_pos], str, len);
((char*)shm_strings.ptr)[shmSettings->next_str_pos + len] = '\0';
// the length (len+1) ensures that we copy the terminator as well
strncpy(&((char*)shm_strings.ptr)[shmSettings->next_str_pos], str, len + 1);
// Increment string length counter
shmSettings->next_str_pos += len+1;