Browse Source

Fix the bug in UTIL_GetFullPathName

This fix the incorrect null-termination bug in UTIL_GetFullPathName,
and reverts commit 0ba84c00daf1d25e2a655a0d03f02608f4064134 which is
not necessary now.
Lou Yihua 6 years ago
parent
commit
dad9f7a497
2 changed files with 4 additions and 2 deletions
  1. 1 1
      mp3play.c
  2. 3 1
      util.c

+ 1 - 1
mp3play.c

@@ -113,7 +113,7 @@ MP3_Play(
 
 	if (iNum > 0)
 	{
-		player->pMP3 = mad_openFile(PAL_CombinePath(0, gConfig.pszGamePath, PAL_va(1, "mp3/%.2d.mp3", iNum)), AUDIO_GetDeviceSpec(), gConfig.iResampleQuality);
+		player->pMP3 = mad_openFile(UTIL_GetFullPathName(PAL_BUFFER_SIZE_ARGS(0), gConfig.pszGamePath, PAL_va(1, "mp3/%.2d.mp3", iNum)), AUDIO_GetDeviceSpec(), gConfig.iResampleQuality);
 
 		if (player->pMP3)
 		{

+ 3 - 1
util.c

@@ -625,7 +625,9 @@ UTIL_GetFullPathName(
 #endif
 	if (result != NULL)
 	{
-		result = (char *)memmove(buffer, result, min(buflen, strlen(result)));
+		size_t dstlen = min(buflen - 1, strlen(result));
+		result = (char *)memmove(buffer, result, dstlen);
+		buffer[dstlen] = '\0';
 	}
 
 	free(_base);