@@ -54,14 +54,12 @@ char *opal_os_path(int relative, ...)
5454 va_end (ap );
5555
5656 if (0 == num_elements ) { /* must be looking for a simple answer */
57- path = ( char * ) malloc ( 3 ) ;
58- path [ 0 ] = '\0' ;
57+ size_t len = 3 ;
58+ path = ( char * ) calloc ( len , sizeof ( char )) ;
5959 if (relative ) {
60- strcpy (path , "." );
61- strcat (path , path_sep );
62- } else {
63- strcpy (path , path_sep );
64- }
60+ path [0 ] = '.' ;
61+ }
62+ strncat (path , path_sep , len );
6563 return (path );
6664 }
6765
@@ -76,28 +74,27 @@ char *opal_os_path(int relative, ...)
7674 return (NULL );
7775 }
7876
79- path = (char * )malloc (total_length );
77+ path = (char * )calloc (total_length , sizeof ( char ) );
8078 if (NULL == path ) {
8179 return (NULL );
8280 }
83- path [0 ] = 0 ;
8481
8582 if (relative ) {
86- strcpy ( path , "." ) ;
83+ path [ 0 ] = '.' ;
8784 }
8885
8986 va_start (ap , relative );
9087 if ( NULL != (element = va_arg (ap , char * )) ) {
9188 if (path_sep [0 ] != element [0 ]) {
92- strcat (path , path_sep );
89+ strncat (path , path_sep , total_length );
9390 }
9491 strcat (path , element );
9592 }
9693 while (NULL != (element = va_arg (ap , char * ))) {
9794 if (path_sep [0 ] != element [0 ]) {
98- strcat (path , path_sep );
95+ strncat (path , path_sep , total_length );
9996 }
100- strcat (path , element );
97+ strncat (path , element , total_length );
10198 }
10299
103100 va_end (ap );
0 commit comments