Skip to content

Commit 5a66132

Browse files
alphagoccclaude
andcommitted
fix: address bugs found in code review
- base/settings: correct misspelled "DefaultOuputFileExtension" key so the user's chosen output extension actually round-trips on save/load - base/settings.h: drop unimplemented temporaryPath() declaration - base/LemonBaseApplication: invert parseCommandLine() return so the hasError branch fires on real errors instead of on success; release the locally-allocated Settings before returning - base/LemonLog: move tempBuffer/tempStream into log_concat() so concurrent log calls no longer race on shared globals - base/LemonTranslator: bail out when QTranslator::load() fails instead of installing an empty translator - core/processrunner_win: fix uniform_int_distribution upper bound (was inclusive of length(), allowing an out-of-range index) - generalsettings: actually return false from checkValid() when rejudgeTimes is empty so invalid input is rejected - lemon: return after the "No Contest Yet" warning in changeContestName to avoid dereferencing a null curContest Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> (cherry picked from commit a6f010d)
1 parent 311f392 commit 5a66132

8 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/base/LemonBaseApplication.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace Lemon;
2222
auto LemonBaseApplication::Initialize() -> bool {
2323
QString errorMessage;
2424
bool canContinue;
25-
const auto hasError = parseCommandLine(&canContinue, &errorMessage);
25+
const auto hasError = ! parseCommandLine(&canContinue, &errorMessage);
2626
if (hasError) {
2727
LOG("Command line: " GEN_PAIR(errorMessage));
2828
if (! canContinue) {
@@ -48,7 +48,7 @@ auto LemonBaseApplication::Initialize() -> bool {
4848
}
4949
}
5050
LemonLimeTranslator->InstallTranslation(settings->getUiLanguage());
51-
51+
delete settings;
5252
return true;
5353
}
5454

src/base/LemonLog.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Q_DECLARE_METATYPE(const char *)
4848

4949
namespace Lemon::base {
5050
inline std::shared_ptr<spdlog::logger> logger;
51-
inline QString tempBuffer;
52-
inline QTextStream tempStream{&tempBuffer};
5351

5452
template <LemonLogType t, typename... T> inline void log_concat(T... v) {
53+
QString tempBuffer;
54+
QTextStream tempStream{&tempBuffer};
5555
((tempStream << v << " "), ...);
5656

5757
const auto logString = tempStream.readAll().toStdString();

src/base/LemonTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace Lemon::common {
5555
bool success = translatorNew->load(code + ".qm", path);
5656
if (! success) {
5757
LOG("Cannot load translation: " + code);
58+
return false;
5859
}
5960
if (pTranslator) {
6061
LOG("Removed translations");

src/base/settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ void Settings::loadSettings() {
533533
rejudgeTimes = settings.value("MaximumRejudgeTimes", 1).toInt();
534534
maxJudgingThreads = settings.value("MaximumJudgingThreads", 1).toInt();
535535
defaultInputFileExtension = settings.value("DefaultInputFileExtension", "in").toString();
536-
defaultOutputFileExtension = settings.value("DefaultOuputFileExtension", "out").toString();
536+
defaultOutputFileExtension = settings.value("DefaultOutputFileExtension", "out").toString();
537537
inputFileExtensions = settings.value("InputFileExtensions", QStringList() << "in").toStringList();
538538
outputFileExtensions =
539539
settings.value("OutputFileExtensions", QStringList() << "out" << "ans").toStringList();

src/base/settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ class Settings {
142142
static double upperBoundForExtraTimeRatio();
143143
static QString dataPath();
144144
static QString sourcePath();
145-
static QString temporaryPath();
146145
static QString selfTestPath();
147146

148147
private:

src/core/processrunner_win.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ namespace {
3939
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
4040
std::mt19937 gen(std::random_device{}());
4141

42-
std::uniform_int_distribution<int> rand(0, possibleCharacters.length());
42+
std::uniform_int_distribution<int> rand(0, // [0, length of possibleCharacters - 1]
43+
possibleCharacters.length() - 1);
4344
QString randomString;
4445
for (int i = 0; i < length; ++i) {
4546
int index = rand(gen) % possibleCharacters.length();

src/generalsettings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ auto GeneralSettings::checkValid() -> bool {
131131
if (ui->rejudgeTimes->text().isEmpty()) {
132132
ui->rejudgeTimes->setFocus();
133133
QMessageBox::warning(this, tr("Error"), tr("Empty maximum rejudge times!"), QMessageBox::Close);
134+
return false;
134135
}
135136

136137
return true;

src/lemon.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,8 @@ void LemonLime::addTaskWithScoreScale(const QString &title,
879879
}
880880
}
881881

882-
auto LemonLime::compareFileName(const std::pair<QString, QString> &a,
883-
const std::pair<QString, QString> &b) -> bool {
882+
auto LemonLime::compareFileName(const std::pair<QString, QString> &a, const std::pair<QString, QString> &b)
883+
-> bool {
884884
return (a.first.length() < b.first.length()) ||
885885
(a.first.length() == b.first.length() && QString::localeAwareCompare(a.first, b.first) < 0);
886886
}
@@ -972,6 +972,7 @@ void LemonLime::exportStatistics() { StatisticsBrowser::exportStatistics(this, c
972972
void LemonLime::changeContestName() {
973973
if (! curContest) {
974974
QMessageBox::warning(this, tr("Rename Contest"), tr("No Contest Yet"));
975+
return;
975976
}
976977

977978
bool confirmed = false;

0 commit comments

Comments
 (0)