File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -1355,10 +1355,21 @@ int __llvm_write_custom_profile(const char *Target,
13551355 TargetFilename =
13561356 (char * )COMPILER_RT_ALLOCA (FilenameLength + TargetLength + 2 );
13571357
1358+ /* Find file basename and path sizes */
1359+ int32_t DirEnd = FilenameLength - 1 ;
1360+ while (DirEnd >= 0 && !IS_DIR_SEPARATOR (Filename [DirEnd ])) {
1361+ DirEnd -- ;
1362+ }
1363+ uint32_t DirSize = DirEnd + 1 , BaseSize = FilenameLength - DirSize ;
1364+
13581365 /* Prepend "TARGET." to current filename */
1359- memcpy (TargetFilename , Target , TargetLength );
1360- TargetFilename [TargetLength ] = '.' ;
1361- memcpy (TargetFilename + 1 + TargetLength , Filename , FilenameLength );
1366+ if (DirSize > 0 ) {
1367+ memcpy (TargetFilename , Filename , DirSize );
1368+ }
1369+ memcpy (TargetFilename + DirSize , Target , TargetLength );
1370+ TargetFilename [TargetLength + DirSize ] = '.' ;
1371+ memcpy (TargetFilename + DirSize + 1 + TargetLength , Filename + DirSize ,
1372+ BaseSize );
13621373 TargetFilename [FilenameLength + 1 + TargetLength ] = 0 ;
13631374
13641375 /* Check if there is llvm/runtime version mismatch. */
You can’t perform that action at this time.
0 commit comments