Skip to content

Commit 86d8191

Browse files
committed
use std::strncpy
1 parent 7ff7632 commit 86d8191

2 files changed

Lines changed: 65 additions & 34 deletions

File tree

gframe/data_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
165165
}
166166
}
167167
bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
168-
errmsg[0] = '\0';
169-
std::strncat(errmsg, sqlite3_errmsg(pDB), sizeof errmsg - 1);
168+
std::strncpy(errmsg, sqlite3_errmsg(pDB), sizeof errmsg);
169+
errmsg[sizeof errmsg - 1] = '\0';
170170
if(pStmt)
171171
sqlite3_finalize(pStmt);
172172
return false;

gframe/sound_manager.cpp

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,134 +89,165 @@ void SoundManager::PlaySoundEffect(int sound) {
8989
char soundName[32];
9090
switch(sound) {
9191
case SOUND_SUMMON: {
92-
strcpy(soundName, "summon");
92+
std::strncpy(soundName, "summon", sizeof soundName);
93+
soundName[sizeof soundName - 1] = 0;
9394
break;
9495
}
9596
case SOUND_SPECIAL_SUMMON: {
96-
strcpy(soundName, "specialsummon");
97+
std::strncpy(soundName, "specialsummon", sizeof soundName);
98+
soundName[sizeof soundName - 1] = 0;
9799
break;
98100
}
99101
case SOUND_ACTIVATE: {
100-
strcpy(soundName, "activate");
102+
std::strncpy(soundName, "activate", sizeof soundName);
103+
soundName[sizeof soundName - 1] = 0;
101104
break;
102105
}
103106
case SOUND_SET: {
104-
strcpy(soundName, "set");
107+
std::strncpy(soundName, "set", sizeof soundName);
108+
soundName[sizeof soundName - 1] = 0;
105109
break;
106110
}
107111
case SOUND_FILP: {
108-
strcpy(soundName, "flip");
112+
std::strncpy(soundName, "flip", sizeof soundName);
113+
soundName[sizeof soundName - 1] = 0;
109114
break;
110115
}
111116
case SOUND_REVEAL: {
112-
strcpy(soundName, "reveal");
117+
std::strncpy(soundName, "reveal", sizeof soundName);
118+
soundName[sizeof soundName - 1] = 0;
113119
break;
114120
}
115121
case SOUND_EQUIP: {
116-
strcpy(soundName, "equip");
122+
std::strncpy(soundName, "equip", sizeof soundName);
123+
soundName[sizeof soundName - 1] = 0;
117124
break;
118125
}
119126
case SOUND_DESTROYED: {
120-
strcpy(soundName, "destroyed");
127+
std::strncpy(soundName, "destroyed", sizeof soundName);
128+
soundName[sizeof soundName - 1] = 0;
121129
break;
122130
}
123131
case SOUND_BANISHED: {
124-
strcpy(soundName, "banished");
132+
std::strncpy(soundName, "banished", sizeof soundName);
133+
soundName[sizeof soundName - 1] = 0;
125134
break;
126135
}
127136
case SOUND_TOKEN: {
128-
strcpy(soundName, "token");
137+
std::strncpy(soundName, "token", sizeof soundName);
138+
soundName[sizeof soundName - 1] = 0;
129139
break;
130140
}
131141
case SOUND_NEGATE: {
132-
strcpy(soundName, "negate");
142+
std::strncpy(soundName, "negate", sizeof soundName);
143+
soundName[sizeof soundName - 1] = 0;
133144
break;
134145
}
135146
case SOUND_ATTACK: {
136-
strcpy(soundName, "attack");
147+
std::strncpy(soundName, "attack", sizeof soundName);
148+
soundName[sizeof soundName - 1] = 0;
137149
break;
138150
}
139151
case SOUND_DIRECT_ATTACK: {
140-
strcpy(soundName, "directattack");
152+
std::strncpy(soundName, "directattack", sizeof soundName);
153+
soundName[sizeof soundName - 1] = 0;
141154
break;
142155
}
143156
case SOUND_DRAW: {
144-
strcpy(soundName, "draw");
157+
std::strncpy(soundName, "draw", sizeof soundName);
158+
soundName[sizeof soundName - 1] = 0;
145159
break;
146160
}
147161
case SOUND_SHUFFLE: {
148-
strcpy(soundName, "shuffle");
162+
std::strncpy(soundName, "shuffle", sizeof soundName);
163+
soundName[sizeof soundName - 1] = 0;
149164
break;
150165
}
151166
case SOUND_DAMAGE: {
152-
strcpy(soundName, "damage");
167+
std::strncpy(soundName, "damage", sizeof soundName);
168+
soundName[sizeof soundName - 1] = 0;
153169
break;
154170
}
155171
case SOUND_RECOVER: {
156-
strcpy(soundName, "gainlp");
172+
std::strncpy(soundName, "gainlp", sizeof soundName);
173+
soundName[sizeof soundName - 1] = 0;
157174
break;
158175
}
159176
case SOUND_COUNTER_ADD: {
160-
strcpy(soundName, "addcounter");
177+
std::strncpy(soundName, "addcounter", sizeof soundName);
178+
soundName[sizeof soundName - 1] = 0;
161179
break;
162180
}
163181
case SOUND_COUNTER_REMOVE: {
164-
strcpy(soundName, "removecounter");
182+
std::strncpy(soundName, "removecounter", sizeof soundName);
183+
soundName[sizeof soundName - 1] = 0;
165184
break;
166185
}
167186
case SOUND_COIN: {
168-
strcpy(soundName, "coinflip");
187+
std::strncpy(soundName, "coinflip", sizeof soundName);
188+
soundName[sizeof soundName - 1] = 0;
169189
break;
170190
}
171191
case SOUND_DICE: {
172-
strcpy(soundName, "diceroll");
192+
std::strncpy(soundName, "diceroll", sizeof soundName);
193+
soundName[sizeof soundName - 1] = 0;
173194
break;
174195
}
175196
case SOUND_NEXT_TURN: {
176-
strcpy(soundName, "nextturn");
197+
std::strncpy(soundName, "nextturn", sizeof soundName);
198+
soundName[sizeof soundName - 1] = 0;
177199
break;
178200
}
179201
case SOUND_PHASE: {
180-
strcpy(soundName, "phase");
202+
std::strncpy(soundName, "phase", sizeof soundName);
203+
soundName[sizeof soundName - 1] = 0;
181204
break;
182205
}
183206
case SOUND_MENU: {
184-
strcpy(soundName, "menu");
207+
std::strncpy(soundName, "menu", sizeof soundName);
208+
soundName[sizeof soundName - 1] = 0;
185209
break;
186210
}
187211
case SOUND_BUTTON: {
188-
strcpy(soundName, "button");
212+
std::strncpy(soundName, "button", sizeof soundName);
213+
soundName[sizeof soundName - 1] = 0;
189214
break;
190215
}
191216
case SOUND_INFO: {
192-
strcpy(soundName, "info");
217+
std::strncpy(soundName, "info", sizeof soundName);
218+
soundName[sizeof soundName - 1] = 0;
193219
break;
194220
}
195221
case SOUND_QUESTION: {
196-
strcpy(soundName, "question");
222+
std::strncpy(soundName, "question", sizeof soundName);
223+
soundName[sizeof soundName - 1] = 0;
197224
break;
198225
}
199226
case SOUND_CARD_PICK: {
200-
strcpy(soundName, "cardpick");
227+
std::strncpy(soundName, "cardpick", sizeof soundName);
228+
soundName[sizeof soundName - 1] = 0;
201229
break;
202230
}
203231
case SOUND_CARD_DROP: {
204-
strcpy(soundName, "carddrop");
232+
std::strncpy(soundName, "carddrop", sizeof soundName);
233+
soundName[sizeof soundName - 1] = 0;
205234
break;
206235
}
207236
case SOUND_PLAYER_ENTER: {
208-
strcpy(soundName, "playerenter");
237+
std::strncpy(soundName, "playerenter", sizeof soundName);
238+
soundName[sizeof soundName - 1] = 0;
209239
break;
210240
}
211241
case SOUND_CHAT: {
212-
strcpy(soundName, "chatmessage");
242+
std::strncpy(soundName, "chatmessage", sizeof soundName);
243+
soundName[sizeof soundName - 1] = 0;
213244
break;
214245
}
215246
default:
216247
break;
217248
}
218249
char soundPath[40];
219-
std::snprintf(soundPath, 40, "./sound/%s.wav", soundName);
250+
std::snprintf(soundPath, sizeof soundPath, "./sound/%s.wav", soundName);
220251
SetSoundVolume(mainGame->gameConf.sound_volume);
221252
#ifdef YGOPRO_USE_MINIAUDIO
222253
ma_engine_play_sound(&engineSound, soundPath, nullptr);

0 commit comments

Comments
 (0)