Skip to content

Commit 036a31a

Browse files
LuLu
authored andcommitted
initialize host_name before use
1 parent 55a29ba commit 036a31a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

source/lmp/pair_nnp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <iostream>
2+
#include <string.h>
23
#include <iomanip>
34
#include <limits>
45
#include "atom.h"
@@ -42,6 +43,7 @@ static int stringCmp(const void *a, const void* b)
4243

4344
int PairNNP::get_node_rank() {
4445
char host_name[MPI_MAX_PROCESSOR_NAME];
46+
memset(host_name, '\0', sizeof(char) * MPI_MAX_PROCESSOR_NAME);
4547
char (*host_names)[MPI_MAX_PROCESSOR_NAME];
4648
int n, namelen, color, rank, nprocs, myrank;
4749
size_t bytes;
@@ -53,6 +55,10 @@ int PairNNP::get_node_rank() {
5355

5456
bytes = nprocs * sizeof(char[MPI_MAX_PROCESSOR_NAME]);
5557
host_names = (char (*)[MPI_MAX_PROCESSOR_NAME]) malloc(bytes);
58+
for (int ii = 0; ii < nprocs; ii++) {
59+
memset(host_names[ii], '\0', sizeof(char) * MPI_MAX_PROCESSOR_NAME);
60+
}
61+
5662
strcpy(host_names[rank], host_name);
5763

5864
for (n=0; n<nprocs; n++)

0 commit comments

Comments
 (0)