@@ -562,7 +562,7 @@ static int prte_rmaps_rank_file_parse(const char *rankfile)
562562 case PRTE_RANKFILE_INT :
563563 case PRTE_RANKFILE_RELATIVE :
564564 if (PRTE_RANKFILE_INT == token ) {
565- sprintf (buff , "%d" , prte_rmaps_rank_file_value .ival );
565+ snprintf (buff ,RMAPS_RANK_FILE_MAX_SLOTS , "%d" , prte_rmaps_rank_file_value .ival );
566566 value = buff ;
567567 } else {
568568 value = prte_rmaps_rank_file_value .sval ;
@@ -627,7 +627,7 @@ static int prte_rmaps_rank_file_parse(const char *rankfile)
627627 goto unlock ;
628628 } else {
629629 /* prepare rank assignment string for the help message in case of a bad-assign */
630- sprintf (tmp_rank_assignment , "%s slot=%s" , node_name , value );
630+ snprintf (tmp_rank_assignment , RMAPS_RANK_FILE_MAX_SLOTS , "%s slot=%s" , node_name , value );
631631 pmix_pointer_array_set_item (assigned_ranks_array , 0 , tmp_rank_assignment );
632632 }
633633
@@ -671,7 +671,7 @@ static char *prte_rmaps_rank_file_parse_string_or_int(void)
671671 case PRTE_RANKFILE_STRING :
672672 return strdup (prte_rmaps_rank_file_value .sval );
673673 case PRTE_RANKFILE_INT :
674- sprintf (tmp_str , "%d" , prte_rmaps_rank_file_value .ival );
674+ snprintf (tmp_str , RMAPS_RANK_FILE_MAX_SLOTS , "%d" , prte_rmaps_rank_file_value .ival );
675675 return strdup (tmp_str );
676676 default :
677677 return NULL ;
@@ -787,7 +787,7 @@ static int prte_rmaps_rf_lsf_convert_affinity_to_rankfile(char *affinity_file, c
787787 // session dir + / (1) + lsf_rf. (7) + XXXXXX (6) + \0 (1)
788788 len = strlen (prte_process_info .top_session_dir ) + 1 + 7 + 6 + 1 ;
789789 (* aff_rankfile ) = (char * ) malloc (sizeof (char ) * len );
790- sprintf (* aff_rankfile , "%s/lsf_rf.XXXXXX" , prte_process_info .top_session_dir );
790+ snprintf (* aff_rankfile , len , "%s/lsf_rf.XXXXXX" , prte_process_info .top_session_dir );
791791
792792 /* open the file */
793793 fp = fopen (affinity_file , "r" );
@@ -882,7 +882,7 @@ static int prte_rmaps_rf_lsf_convert_affinity_to_rankfile(char *affinity_file, c
882882 free (cpus [i ]);
883883 // 10 max number of digits in an int
884884 cpus [i ] = (char * )malloc (sizeof (char ) * 10 );
885- sprintf (cpus [i ], "%d" , obj -> logical_index );
885+ snprintf (cpus [i ], 10 , "%d" , obj -> logical_index );
886886 }
887887 sep = PMIX_ARGV_JOIN_COMPAT (cpus , ',' );
888888 PMIX_ARGV_FREE_COMPAT (cpus );
@@ -893,7 +893,7 @@ static int prte_rmaps_rf_lsf_convert_affinity_to_rankfile(char *affinity_file, c
893893 // "rank " (5) + id (max 10) + = (1) + host (?) + " slot=" (6) + ids (?) + '\0' (1)
894894 len = 5 + 10 + 1 + strlen (hstname ) + 6 + strlen (sep ) + 1 ;
895895 tmp_str = (char * )malloc (sizeof (char ) * len );
896- sprintf (tmp_str , "rank %d=%s slot=%s\n" , cur_rank , hstname , sep );
896+ snprintf (tmp_str , len , "rank %d=%s slot=%s\n" , cur_rank , hstname , sep );
897897 pmix_fd_write (fp_rank , strlen (tmp_str ), tmp_str );
898898 free (tmp_str );
899899 ++ cur_rank ;
0 commit comments