Skip to content

Commit

Permalink
Merge pull request #18248 from hrydgard/assorted-fixes-12
Browse files Browse the repository at this point in the history
More assorted fixes
  • Loading branch information
hrydgard committed Sep 27, 2023
2 parents 1fff976 + 84d0236 commit 43ae1e3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Common/Data/Text/I18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ class I18NRepo {
std::string LanguageID();

std::shared_ptr<I18NCategory> GetCategory(I18NCat category);
std::shared_ptr<I18NCategory> GetCategoryByName(const char *name);

// Translate the string, by looking up "key" in the file, and falling back to either def or key, in that order, if the lookup fails.
// def can (and usually is) set to nullptr.
const char *T(I18NCat category, const char *key, const char *def = nullptr) {
if (category == I18NCat::NONE)
return def ? def : key;
Expand Down
6 changes: 5 additions & 1 deletion Common/UI/PopupScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ void PopupMultiChoice::UpdateText() {
if (index < 0 || index >= numChoices_) {
valueText_ = "(invalid choice)"; // Shouldn't happen. Should be no need to translate this.
} else {
valueText_ = T(category_, choices_[index]);
if (choices_[index]) {
valueText_ = T(category_, choices_[index]);
} else {
valueText_ = "";
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/ARM/ArmJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ void ArmJit::UpdateRoundingMode(u32 fcr31) {
// I don't think this gives us that much benefit.
void ArmJit::WriteExit(u32 destination, int exit_num)
{
// TODO: Check destination is valid and trigger exception.
// NOTE: Can't blindly check for bad destination addresses here, sometimes exits with bad destinations are written intentionally (like breaks).
_assert_msg_(exit_num < MAX_JIT_BLOCK_EXITS, "Expected a valid exit_num. dest=%08x", destination);

WriteDownCount();
Expand Down
6 changes: 3 additions & 3 deletions Core/MIPS/ARM64/Arm64Jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,11 @@ void Arm64Jit::UpdateRoundingMode(u32 fcr31) {
// though, as we need to have the SUBS flag set in the end. So with block linking in the mix,
// I don't think this gives us that much benefit.
void Arm64Jit::WriteExit(u32 destination, int exit_num) {
// TODO: Check destination is valid and trigger exception.
// NOTE: Can't blindly check for bad destination addresses here, sometimes exits with bad destinations are written intentionally (like breaks).
_assert_msg_(exit_num < MAX_JIT_BLOCK_EXITS, "Expected a valid exit_num. dest=%08x", destination);

// TODO: Check destination is valid and trigger exception.
WriteDownCount();
// NOTE: Can't blindly check for bad destination addresses here, sometimes exits with bad destinations are written intentionally (like breaks).
WriteDownCount();
//If nobody has taken care of this yet (this can be removed when all branches are done)
JitBlock *b = js.curBlock;
b->exitAddress[exit_num] = destination;
Expand Down
5 changes: 5 additions & 0 deletions Core/MIPS/JitCommon/JitBlockCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ void JitBlockCache::UnlinkBlock(int i) {
if (ppp.first == ppp.second)
return;
for (auto iter = ppp.first; iter != ppp.second; ++iter) {
if ((size_t)iter->second >= num_blocks_) {
// Something probably went very wrong. Try to stumble along nevertheless.
ERROR_LOG(JIT, "UnlinkBlock: Invalid block number %d", iter->second);
continue;
}
JitBlock &sourceBlock = blocks_[iter->second];
for (int e = 0; e < MAX_JIT_BLOCK_EXITS; e++) {
if (sourceBlock.exitAddress[e] == b.originalAddress)
Expand Down
7 changes: 6 additions & 1 deletion UI/BackgroundAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void WavData::Read(RIFFReader &file_) {

raw_data = (uint8_t *)malloc(numBytes);
raw_data_size = numBytes;

if (num_channels == 1 || num_channels == 2) {
file_.ReadData(raw_data, numBytes);
} else {
Expand Down Expand Up @@ -410,7 +411,11 @@ Sample *Sample::Load(const std::string &path) {
samples[i] = ConvertU8ToI16(wave.raw_data[i]);
}
}
return new Sample(samples, wave.num_channels, wave.numFrames, wave.sample_rate);

// Protect against bad metadata.
int actualFrames = std::min(wave.numFrames, wave.raw_data_size / wave.raw_bytes_per_frame);

return new Sample(samples, wave.num_channels, actualFrames, wave.sample_rate);
}

static inline int16_t Clamp16(int32_t sample) {
Expand Down
4 changes: 2 additions & 2 deletions UI/RemoteISOScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ void RemoteISOConnectScreen::ExecuteLoad() {

class RemoteGameBrowser : public GameBrowser {
public:
RemoteGameBrowser(const Path &url, BrowseFlags browseFlags, bool *gridStyle_, ScreenManager *screenManager, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = nullptr)
: GameBrowser(url, browseFlags, gridStyle_, screenManager, lastText, lastLink, layoutParams) {
RemoteGameBrowser(const Path &url, BrowseFlags browseFlags, bool *gridStyle, ScreenManager *screenManager, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = nullptr)
: GameBrowser(url, browseFlags, gridStyle, screenManager, lastText, lastLink, layoutParams) {
initialPath_ = url;
}

Expand Down

0 comments on commit 43ae1e3

Please sign in to comment.