Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit 5e02b6d

Browse files
committed
ompi: fixup hostname max length usage
Signed-off-by: Karol Mroz <[email protected]> (cherry picked from commit 3322347)
1 parent ddb60c6 commit 5e02b6d

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

ompi/info/info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ opal_pointer_array_t ompi_info_f_to_c_table = {{0}};
9595
*/
9696
int ompi_info_init(void)
9797
{
98-
char val[MPI_MAX_INFO_VAL];
98+
char val[OPAL_MAXHOSTNAMELEN];
9999
char *cptr;
100100

101101
/* initialize table */
@@ -134,7 +134,7 @@ int ompi_info_init(void)
134134
}
135135

136136
/* local host name */
137-
gethostname(val, MPI_MAX_INFO_VAL);
137+
gethostname(val, sizeof(val));
138138
ompi_info_set(&ompi_mpi_info_env.info, "host", val);
139139

140140
/* architecture name */

ompi/mca/pml/v/pml_v_output.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
int pml_v_output_open(char *output, int verbosity) {
2323
opal_output_stream_t lds;
24-
char hostname[32] = "NA";
24+
char hostname[OPAL_MAXHOSTNAMELEN] = "NA";
2525

2626
OBJ_CONSTRUCT(&lds, opal_output_stream_t);
2727
if(!output) {
@@ -40,7 +40,7 @@ int pml_v_output_open(char *output, int verbosity) {
4040
lds.lds_file_suffix = output;
4141
}
4242
lds.lds_is_debugging = true;
43-
gethostname(hostname, 32);
43+
gethostname(hostname, sizeof(hostname));
4444
asprintf(&lds.lds_prefix, "[%s:%05d] pml_v: ", hostname, getpid());
4545
lds.lds_verbose_level = verbosity;
4646
mca_pml_v.output = opal_output_open(&lds);

ompi/mpi/c/get_processor_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int MPI_Get_processor_name(char *name, int *resultlen)
6464
Guard against gethostname() returning a *really long* hostname
6565
and not null-terminating the string. The Fortran API version
6666
will pad to the right if necessary. */
67-
gethostname(name, MPI_MAX_PROCESSOR_NAME - 1);
67+
gethostname(name, (MPI_MAX_PROCESSOR_NAME - 1));
6868
name[MPI_MAX_PROCESSOR_NAME - 1] = '\0';
6969
*resultlen = (int) strlen(name);
7070

ompi/runtime/ompi_mpi_abort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int
119119
ompi_mpi_abort(struct ompi_communicator_t* comm,
120120
int errcode)
121121
{
122-
char *msg, *host, hostname[MAXHOSTNAMELEN];
122+
char *msg, *host, hostname[OPAL_MAXHOSTNAMELEN];
123123
pid_t pid = 0;
124124

125125
/* Protection for recursive invocation */

ompi/runtime/ompi_mpi_finalize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int ompi_mpi_finalize(void)
114114
/* Note that if we're not initialized or already finalized, we
115115
cannot raise an MPI exception. The best that we can do is
116116
write something to stderr. */
117-
char hostname[MAXHOSTNAMELEN];
117+
char hostname[OPAL_MAXHOSTNAMELEN];
118118
pid_t pid = getpid();
119119
gethostname(hostname, sizeof(hostname));
120120

ompi/tools/mpisync/sync.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
6969
MPI_Comm comm = MPI_COMM_WORLD;
7070
int rank, commsize;
7171
double offs = 0, rtt = 0;
72-
char hname[1024];
72+
char hname[OPAL_MAXHOSTNAMELEN];
7373

7474
MPI_Comm_rank(comm, &rank);
7575
MPI_Comm_size(comm, &commsize);
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
9393
exit(1);
9494
}
9595

96-
if( gethostname(hname, 1024) ){
96+
if( gethostname(hname, sizeof(hname)) ){
9797
perror("Cannot get hostname. Abort");
9898
MPI_Abort(MPI_COMM_WORLD, 1);
9999
}
@@ -114,13 +114,13 @@ int main(int argc, char **argv)
114114
fprintf(stderr, "Fail to allocate memory. Abort\n");
115115
MPI_Abort(MPI_COMM_WORLD, 1);
116116
}
117-
char *hnames = malloc(1024*commsize);
117+
char *hnames = malloc(OPAL_MAXHOSTNAMELEN * commsize);
118118
if( hnames == NULL ){
119119
fprintf(stderr, "Fail to allocate memory. Abort\n");
120120
MPI_Abort(MPI_COMM_WORLD, 1);
121121
}
122122

123-
MPI_Gather(hname,1024,MPI_CHAR,hnames,1024,MPI_CHAR, 0, MPI_COMM_WORLD);
123+
MPI_Gather(hname,sizeof(hname),MPI_CHAR,hnames,sizeof(hname),MPI_CHAR, 0, MPI_COMM_WORLD);
124124
MPI_Gather(send,2,MPI_DOUBLE,measure,2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
125125
char tmpname[128];
126126
FILE *fp = fopen(filename,"w");
@@ -129,14 +129,14 @@ int main(int argc, char **argv)
129129
MPI_Abort(MPI_COMM_WORLD, 1);
130130
}
131131
double (*m)[2] = (void*)measure;
132-
char (*h)[1024] = (void*)hnames;
132+
char (*h)[OPAL_MAXHOSTNAMELEN] = (void*)hnames;
133133
int i;
134134
for(i=0; i<commsize;i++){
135135
fprintf(fp, "%s %lf %lf\n", h[i], m[i][0], m[i][1]);
136136
}
137137
fclose(fp);
138138
} else {
139-
MPI_Gather(hname,1024, MPI_CHAR, NULL, 1024, MPI_CHAR, 0, MPI_COMM_WORLD);
139+
MPI_Gather(hname, sizeof(hname), MPI_CHAR, NULL, sizeof(hname), MPI_CHAR, 0, MPI_COMM_WORLD);
140140
MPI_Gather(send,2, MPI_DOUBLE, NULL, 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
141141
}
142142

0 commit comments

Comments
 (0)