|
23 | 23 | #include <string.h> |
24 | 24 | #include <math.h> |
25 | 25 |
|
| 26 | +#include <compat/strl.h> |
| 27 | + |
26 | 28 | #include "fceu-types.h" |
27 | 29 | #include "x6502.h" |
28 | 30 | #include "fceu.h" |
@@ -166,9 +168,9 @@ static int LoadNSF(FCEUFILE *fp) { |
166 | 168 | /* NULL-terminate strings just in case. */ |
167 | 169 | NSFHeader.GameName[31] = NSFHeader.Artist[31] = NSFHeader.Copyright[31] = 0; |
168 | 170 |
|
169 | | - sprintf((char *)NSFInfo->SongName, "%s", (const char *)NSFHeader.GameName); |
170 | | - sprintf((char *)NSFInfo->Artist, "%s", (const char *)NSFHeader.Artist); |
171 | | - sprintf((char *)NSFInfo->Copyright, "%s", (const char *)NSFHeader.Copyright); |
| 171 | + snprintf((char *)NSFInfo->SongName, sizeof(NSFInfo->SongName), "%s", (const char *)NSFHeader.GameName); |
| 172 | + snprintf((char *)NSFInfo->Artist, sizeof(NSFInfo->Artist), "%s", (const char *)NSFHeader.Artist); |
| 173 | + snprintf((char *)NSFInfo->Copyright, sizeof(NSFInfo->Copyright), "%s", (const char *)NSFHeader.Copyright); |
172 | 174 |
|
173 | 175 | NSFInfo->LoadAddr = NSFHeader.LoadAddressLow | (NSFHeader.LoadAddressHigh << 8); |
174 | 176 | NSFInfo->InitAddr = NSFHeader.InitAddressLow | (NSFHeader.InitAddressHigh << 8); |
@@ -785,7 +787,7 @@ void DrawNSF(uint8_t *target) { |
785 | 787 | } else { |
786 | 788 | DrawTextTrans(target + 70 * 256 + 4 + (((31 - strlen("Song:")) << 2)), 256, (uint8_t *)"Song:", textColor); |
787 | 789 | } |
788 | | - sprintf(snbuf, "<%d/%d>", NSFInfo->CurrentSong + 1, NSFInfo->TotalSongs); |
| 790 | + snprintf(snbuf, sizeof(snbuf), "<%d/%d>", NSFInfo->CurrentSong + 1, NSFInfo->TotalSongs); |
789 | 791 | DrawTextTrans(target + 82 * 256 + 4 + (((31 - strlen(snbuf)) << 2)), 256, (uint8_t *)snbuf, textColor); |
790 | 792 | } |
791 | 793 |
|
@@ -852,8 +854,8 @@ int FCEUI_NSFChange(int amount) { |
852 | 854 |
|
853 | 855 | /* Returns total songs */ |
854 | 856 | int FCEUI_NSFGetInfo(uint8_t *name, uint8_t *artist, uint8_t *copyright, int maxlen) { |
855 | | - strncpy((char *)name, (const char *)NSFInfo->SongName, (size_t)maxlen); |
856 | | - strncpy((char *)artist, (const char *)NSFInfo->Artist, (size_t)maxlen); |
857 | | - strncpy((char *)copyright, (const char *)NSFInfo->Copyright, (size_t)maxlen); |
| 857 | + strlcpy((char *)name, (const char *)NSFInfo->SongName, (size_t)maxlen); |
| 858 | + strlcpy((char *)artist, (const char *)NSFInfo->Artist, (size_t)maxlen); |
| 859 | + strlcpy((char *)copyright, (const char *)NSFInfo->Copyright, (size_t)maxlen); |
858 | 860 | return (NSFInfo->TotalSongs); |
859 | 861 | } |
0 commit comments