Skip to content

Commit 141d6fc

Browse files
committed
snprintf: ignore some compiler warnings
Compilers are fairly unhelpful when telling us that it's possible that an snprintf() may truncate its copy if it can tell at compile time that the length of the source strings may be longer than the destination string. We know! That's why we're using snprintf()! Instead of explicitly using opal_snprintf() to get around the warning, use the gcc compile flag -Wformat-truncation=0 to disable this warning when in picky mode. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent 314afee commit 141d6fc

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

config/opal_setup_cc.m4

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ AC_DEFUN([OPAL_SETUP_CC],[
303303
_OPAL_CHECK_SPECIFIC_CFLAGS(-fno-strict-aliasing, fno_strict_aliasing, int main() { long double x; })
304304
_OPAL_CHECK_SPECIFIC_CFLAGS(-pedantic, pedantic)
305305
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wall, Wall)
306+
307+
# There are some warnings that we specifically do not care
308+
# about / do not agree that gcc emits warnings about them. So
309+
# we turn them off.
310+
_OPAL_CHECK_SPECIFIC_CFLAGS(-Wformat-truncation=0, format_truncation)
306311
fi
307312

308313
# Note: Some versions of clang (at least >= 3.5 -- perhaps

ompi/mpi/c/type_create_f90_complex.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2006-2009 Sun Microsystems, Inc. All rights reserved.
14-
* Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved
14+
* Copyright (c) 2008-2021 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2015 Research Organization for Information Science
@@ -112,12 +112,8 @@ int MPI_Type_create_f90_complex(int p, int r, MPI_Datatype *newtype)
112112
*/
113113
datatype->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED;
114114
/* Mark the datatype as a special F90 convenience type */
115-
// Specifically using opal_snprintf() here (instead of
116-
// snprintf()) so that over-eager compilers do not warn us
117-
// that we may be truncating the output. We *know* that the
118-
// output may be truncated, and that's ok.
119-
opal_snprintf(datatype->name, sizeof(datatype->name),
120-
"COMBINER %s", (*newtype)->name);
115+
snprintf(datatype->name, sizeof(datatype->name),
116+
"COMBINER %s", (*newtype)->name);
121117

122118
a_i[0] = &p;
123119
a_i[1] = &r;

ompi/mpi/c/type_create_f90_integer.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2006-2009 Sun Microsystems, Inc. All rights reserved.
14-
* Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved
14+
* Copyright (c) 2008-2021 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2015 Research Organization for Information Science
@@ -104,12 +104,8 @@ int MPI_Type_create_f90_integer(int r, MPI_Datatype *newtype)
104104
*/
105105
datatype->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED;
106106
/* Mark the datatype as a special F90 convenience type */
107-
// Specifically using opal_snprintf() here (instead of
108-
// snprintf()) so that over-eager compilers do not warn us
109-
// that we may be truncating the output. We *know* that the
110-
// output may be truncated, and that's ok.
111-
opal_snprintf(datatype->name, sizeof(datatype->name),
112-
"COMBINER %s", (*newtype)->name);
107+
snprintf(datatype->name, sizeof(datatype->name),
108+
"COMBINER %s", (*newtype)->name);
113109

114110
a_i[0] = &r;
115111
ompi_datatype_set_args( datatype, 1, a_i, 0, NULL, 0, NULL, MPI_COMBINER_F90_INTEGER );

ompi/mpi/c/type_create_f90_real.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2006-2009 Sun Microsystems, Inc. All rights reserved.
14-
* Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved
14+
* Copyright (c) 2008-2021 Cisco Systems, Inc. All rights reserved
1515
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights
1616
* reserved.
1717
* Copyright (c) 2015 Research Organization for Information Science
@@ -112,12 +112,8 @@ int MPI_Type_create_f90_real(int p, int r, MPI_Datatype *newtype)
112112
*/
113113
datatype->super.flags |= OMPI_DATATYPE_FLAG_PREDEFINED;
114114
/* Mark the datatype as a special F90 convenience type */
115-
// Specifically using opal_snprintf() here (instead of
116-
// snprintf()) so that over-eager compilers do not warn us
117-
// that we may be truncating the output. We *know* that the
118-
// output may be truncated, and it's ok.
119-
opal_snprintf(datatype->name, sizeof(datatype->name),
120-
"COMBINER %s", (*newtype)->name);
115+
snprintf(datatype->name, sizeof(datatype->name),
116+
"COMBINER %s", (*newtype)->name);
121117

122118
ompi_datatype_set_args( datatype, 2, a_i, 0, NULL, 0, NULL, MPI_COMBINER_F90_REAL );
123119

0 commit comments

Comments
 (0)