Skip to content

Commit 0eab926

Browse files
committed
Slight adjustments to some sprintf calls
1 parent 0748208 commit 0eab926

File tree

2 files changed

+89
-79
lines changed

2 files changed

+89
-79
lines changed

ttyd-tools/rel/source/draw.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,22 +1681,24 @@ void drawMemoryChangeAddressList()
16811681
// Draw the offset being applied
16821682
// Check if the value is negative
16831683
int32_t tempOffset = MemoryWatch[tempMenuSelectedOption].AddressOffset[i - 1];
1684+
1685+
const char *Format;
16841686
if (tempOffset < 0)
16851687
{
1686-
// Conver the value to negative
1688+
// Convert the value to negative
16871689
tempOffset = -tempOffset;
16881690

1689-
sprintf(tempDisplayBuffer,
1690-
"-0x%" PRIX32,
1691-
tempOffset);
1691+
Format = "-0x%" PRIX32;
16921692
}
16931693
else
16941694
{
1695-
sprintf(tempDisplayBuffer,
1696-
"0x%" PRIX32,
1697-
tempOffset);
1695+
Format = "0x%" PRIX32;
16981696
}
16991697

1698+
sprintf(tempDisplayBuffer,
1699+
Format,
1700+
tempOffset);
1701+
17001702
drawText(tempDisplayBuffer, PosX + PosX_Offset_Position, PosY, Alpha, Color, Scale);
17011703

17021704
// Draw the address pointed to by the current level
@@ -3808,6 +3810,13 @@ void drawButtonInputs()
38083810
uint32_t ButtonInput = ttyd::system::keyGetButton(0);
38093811
char *tempDisplayBuffer = DisplayBuffer;
38103812

3813+
const char *Format;
3814+
#ifdef TTYD_JP
3815+
Format = "%s";
3816+
#else
3817+
Format = "%c";
3818+
#endif
3819+
38113820
uint32_t Counter = 0;
38123821
for (uint32_t i = 0; i < 13; i++)
38133822
{
@@ -3819,15 +3828,9 @@ void drawButtonInputs()
38193828

38203829
if (ButtonInput & (1 << i))
38213830
{
3822-
#ifdef TTYD_JP
38233831
sprintf(tempDisplayBuffer,
3824-
"%s",
3832+
Format,
38253833
ButtonInputDisplay[Counter]);
3826-
#else
3827-
sprintf(tempDisplayBuffer,
3828-
"%c",
3829-
ButtonInputDisplay[Counter]);
3830-
#endif
38313834

38323835
drawText(tempDisplayBuffer, PosX, PosY, Alpha, Color, Scale);
38333836
}

ttyd-tools/rel/source/memorywatch.cpp

Lines changed: 72 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int32_t getEmptyWatchSlot()
1717
int32_t Size = sizeof(MemoryWatch) / sizeof(MemoryWatch[0]);
1818
for (int32_t i = 0; i < Size; i++)
1919
{
20-
if (MemoryWatch[i].Address == 0)
20+
if (!MemoryWatch[i].Address)
2121
{
2222
return i;
2323
}
@@ -112,6 +112,7 @@ const char *getValueString(int32_t slot)
112112
bool ShowAsHex = MemoryWatch[slot].ShowAsHex;
113113
char *tempDisplayBuffer = DisplayBuffer;
114114

115+
const char *Format;
115116
switch (MemoryWatch[slot].Type)
116117
{
117118
case string:
@@ -139,165 +140,171 @@ const char *getValueString(int32_t slot)
139140
// Handle the value as unsigned
140141
uint64_t CurrentTimeUnsigned = static_cast<uint64_t>(CurrentTime);
141142

142-
uint32_t hour = CurrentTimeUnsigned / 3600 / FPS;
143-
uint32_t minute = (CurrentTimeUnsigned / 60 / FPS) % 60;
144-
uint32_t second = (CurrentTimeUnsigned / FPS) % 60;
145-
uint32_t frame = CurrentTimeUnsigned % FPS;
143+
uint32_t Hour = CurrentTimeUnsigned / 3600 / FPS;
144+
uint32_t Minute = (CurrentTimeUnsigned / 60 / FPS) % 60;
145+
uint32_t Second = (CurrentTimeUnsigned / FPS) % 60;
146+
uint32_t Frame = CurrentTimeUnsigned % FPS;
146147

147148
if (ValueIsPositive)
148149
{
149-
sprintf(tempDisplayBuffer,
150-
"%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%02" PRIu32,
151-
hour,
152-
minute,
153-
second,
154-
frame);
150+
Format = "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%02" PRIu32;
155151
}
156152
else
157153
{
158-
sprintf(tempDisplayBuffer,
159-
"-%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%02" PRIu32,
160-
hour,
161-
minute,
162-
second,
163-
frame);
154+
Format = "-%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%02" PRIu32;
164155
}
156+
157+
sprintf(tempDisplayBuffer,
158+
Format,
159+
Hour,
160+
Minute,
161+
Second,
162+
Frame);
163+
165164
return tempDisplayBuffer;
166165
}
167166
case s8:
168167
{
169168
int8_t Value = *reinterpret_cast<int8_t *>(Address);
170169
if (ShowAsHex)
171170
{
172-
sprintf(tempDisplayBuffer,
173-
"0x%02" PRIX8,
174-
Value);
171+
Format = "0x%02" PRIX8;
175172
}
176173
else
177174
{
178-
sprintf(tempDisplayBuffer,
179-
"%" PRId8,
180-
Value);
175+
Format = "%" PRId8;
181176
}
177+
178+
sprintf(tempDisplayBuffer,
179+
Format,
180+
Value);
181+
182182
return tempDisplayBuffer;
183183
}
184184
case s16:
185185
{
186186
int16_t Value = *reinterpret_cast<int16_t *>(Address);
187187
if (ShowAsHex)
188188
{
189-
sprintf(tempDisplayBuffer,
190-
"0x%04" PRIX16,
191-
Value);
189+
Format = "0x%04" PRIX16;
192190
}
193191
else
194192
{
195-
sprintf(tempDisplayBuffer,
196-
"%" PRId16,
197-
Value);
193+
Format = "%" PRId16;
198194
}
195+
196+
sprintf(tempDisplayBuffer,
197+
Format,
198+
Value);
199+
199200
return tempDisplayBuffer;
200201
}
201202
case s32:
202203
{
203204
int32_t Value = *reinterpret_cast<int32_t *>(Address);
204205
if (ShowAsHex)
205206
{
206-
sprintf(tempDisplayBuffer,
207-
"0x%08" PRIX32,
208-
Value);
207+
Format = "0x%08" PRIX32;
209208
}
210209
else
211210
{
212-
sprintf(tempDisplayBuffer,
213-
"%" PRId32,
214-
Value);
211+
Format = "%" PRId32;
215212
}
213+
214+
sprintf(tempDisplayBuffer,
215+
Format,
216+
Value);
217+
216218
return tempDisplayBuffer;
217219
}
218220
case s64:
219221
{
220222
int64_t Value = *reinterpret_cast<int64_t *>(Address);
221223
if (ShowAsHex)
222224
{
223-
sprintf(tempDisplayBuffer,
224-
"0x%016" PRIX64,
225-
Value);
225+
Format = "0x%016" PRIX64;
226226
}
227227
else
228228
{
229-
sprintf(tempDisplayBuffer,
230-
"%" PRId64,
231-
Value);
229+
Format = "%" PRId64;
232230
}
231+
232+
sprintf(tempDisplayBuffer,
233+
Format,
234+
Value);
235+
233236
return tempDisplayBuffer;
234237
}
235238
case u8:
236239
{
237240
uint8_t Value = *reinterpret_cast<uint8_t *>(Address);
238241
if (ShowAsHex)
239242
{
240-
sprintf(tempDisplayBuffer,
241-
"0x%02" PRIX8,
242-
Value);
243+
Format = "0x%02" PRIX8;
243244
}
244245
else
245246
{
246-
sprintf(tempDisplayBuffer,
247-
"%" PRIu8,
248-
Value);
247+
Format = "%" PRIu8;
249248
}
249+
250+
sprintf(tempDisplayBuffer,
251+
Format,
252+
Value);
253+
250254
return tempDisplayBuffer;
251255
}
252256
case u16:
253257
{
254258
uint16_t Value = *reinterpret_cast<uint16_t *>(Address);
255259
if (ShowAsHex)
256260
{
257-
sprintf(tempDisplayBuffer,
258-
"0x%04" PRIX16,
259-
Value);
261+
Format = "0x%04" PRIX16;
260262
}
261263
else
262264
{
263-
sprintf(tempDisplayBuffer,
264-
"%" PRIu16,
265-
Value);
265+
Format = "%" PRIu16;
266266
}
267+
268+
sprintf(tempDisplayBuffer,
269+
Format,
270+
Value);
271+
267272
return tempDisplayBuffer;
268273
}
269274
case u32:
270275
{
271276
uint32_t Value = *reinterpret_cast<uint32_t *>(Address);
272277
if (ShowAsHex)
273278
{
274-
sprintf(tempDisplayBuffer,
275-
"0x%08" PRIX32,
276-
Value);
279+
Format = "0x%08" PRIX32;
277280
}
278281
else
279282
{
280-
sprintf(tempDisplayBuffer,
281-
"%" PRIu32,
282-
Value);
283+
Format = "%" PRIu32;
283284
}
285+
286+
sprintf(tempDisplayBuffer,
287+
Format,
288+
Value);
289+
284290
return tempDisplayBuffer;
285291
}
286292
case u64:
287293
{
288294
uint64_t Value = *reinterpret_cast<uint64_t *>(Address);
289295
if (ShowAsHex)
290296
{
291-
sprintf(tempDisplayBuffer,
292-
"0x%016" PRIX64,
293-
Value);
297+
Format = "0x%016" PRIX64;
294298
}
295299
else
296300
{
297-
sprintf(tempDisplayBuffer,
298-
"%" PRIu64,
299-
Value);
301+
Format = "%" PRIu64;
300302
}
303+
304+
sprintf(tempDisplayBuffer,
305+
Format,
306+
Value);
307+
301308
return tempDisplayBuffer;
302309
}
303310
case f32:

0 commit comments

Comments
 (0)