Compare commits

...

3 Commits

Author SHA1 Message Date
lightningterror
c4a8fc5b71 Qt: Fix Winconsistent-missing-override warning. 2025-06-11 23:17:53 +02:00
GovanifY
8eb46b5a4c IopBios: remove clang deprecated carveout
we use snprintf now, so this isn't useful anymore.
2025-06-10 20:59:25 +02:00
GovanifY
8be16d1039 IopBios: do not overflow snprintf tmp buffer
We could otherwise overflow as snprintf does not return the number of
written bytes but the number of written bytes assuming an infinite
buffer.
2025-06-10 20:59:25 +02:00
2 changed files with 8 additions and 17 deletions

View File

@@ -92,7 +92,7 @@ public Q_SLOTS:
void refreshGridCovers();
protected:
void resizeEvent(QResizeEvent* event);
void resizeEvent(QResizeEvent* event) override;
bool event(QEvent* event) override;
private:

View File

@@ -21,6 +21,7 @@
#include <cstring>
#include <fmt/format.h>
#include <sys/stat.h>
#include <algorithm>
#include <fcntl.h>
@@ -928,12 +929,6 @@ namespace R3000A
{
int Kprintf_HLE()
{
// Using sprintf here is a bit nasty, but it has a large buffer..
// Don't feel like rewriting it.
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
// Emulate the expected Kprintf functionality:
iopMemWrite32(sp, a0);
@@ -956,7 +951,7 @@ namespace R3000A
char tmp[max_len], tmp2[max_len];
char* ptmp = tmp;
unsigned int printed_bytes = 0;
unsigned int remaining_buf = max_len - 1;
int remaining_buf = max_len - 1;
int n = 1, i = 0, j = 0;
while (fmt[i])
@@ -1000,7 +995,7 @@ namespace R3000A
{
case 'f':
case 'F':
printed_bytes = snprintf(ptmp, remaining_buf, tmp2, (float)iopMemRead32(sp + n * 4));
printed_bytes = std::min(remaining_buf, snprintf(ptmp, remaining_buf, tmp2, (float)iopMemRead32(sp + n * 4)));
remaining_buf -= printed_bytes;
ptmp += printed_bytes;
n++;
@@ -1012,7 +1007,7 @@ namespace R3000A
case 'E':
case 'g':
case 'G':
printed_bytes = snprintf(ptmp, remaining_buf, tmp2, (double)iopMemRead32(sp + n * 4));
printed_bytes = std::min(remaining_buf, snprintf(ptmp, remaining_buf, tmp2, (double)iopMemRead32(sp + n * 4)));
remaining_buf -= printed_bytes;
ptmp += printed_bytes;
n++;
@@ -1028,14 +1023,14 @@ namespace R3000A
case 'X':
case 'u':
case 'U':
printed_bytes = snprintf(ptmp, remaining_buf, tmp2, (u32)iopMemRead32(sp + n * 4));
printed_bytes = std::min(remaining_buf, snprintf(ptmp, remaining_buf, tmp2, (u32)iopMemRead32(sp + n * 4)));
remaining_buf -= printed_bytes;
ptmp += printed_bytes;
n++;
break;
case 'c':
printed_bytes = snprintf(ptmp, remaining_buf, tmp2, (u8)iopMemRead32(sp + n * 4));
printed_bytes = std::min(remaining_buf, snprintf(ptmp, remaining_buf, tmp2, (u8)iopMemRead32(sp + n * 4)));
remaining_buf -= printed_bytes;
ptmp += printed_bytes;
n++;
@@ -1044,7 +1039,7 @@ namespace R3000A
case 's':
{
std::string s = iopMemReadString(iopMemRead32(sp + n * 4));
printed_bytes = snprintf(ptmp, remaining_buf, tmp2, s.data());
printed_bytes = std::min(remaining_buf, snprintf(ptmp, remaining_buf, tmp2, s.data()));
remaining_buf -= printed_bytes;
ptmp += printed_bytes;
n++;
@@ -1070,10 +1065,6 @@ namespace R3000A
iopConLog(ShiftJIS_ConvertString(tmp, 1023));
return 1;
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
} // namespace sysmem