Skip to content

Commit

Permalink
fix: audit for-loop usage (#965)
Browse files Browse the repository at this point in the history
* fix: use correct comparator in for loop

No functional change -- the same Lua code is emitted due to an
error in `tstolua`, but the code is now correct in the TypeScript.

* fix: modify for loop to match intentions

The local _repeat function is meant to repeat a string N times, so
adjust the loop limits appropriately to do that.

This is a small functional change where previously due to an error
in codegen by `tstolua`, `_repeat(s, 1)` would return `s + s`
instead of just `s`, even though the TypeScript was correct.
However, the exported function `printRepeat` is only used in an
unused `toString` method of the `SimulationCraft` class, so there
is no functional impact.
  • Loading branch information
johnnylam88 committed Aug 12, 2021
1 parent 3343a47 commit 2e7a5ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/engine/scripts.ts
Expand Up @@ -224,9 +224,8 @@ export class OvaleScriptsClass {
}

setCurrentSpecScript(scriptName: string) {
this.ovaleOptions.db.profile.source[
this.getCurrentSpecScriptId()
] = scriptName;
this.ovaleOptions.db.profile.source[this.getCurrentSpecScriptId()] =
scriptName;
}

createOptions() {
Expand Down Expand Up @@ -340,7 +339,7 @@ export class OvaleScriptsClass {
if (!isLuaArray(this.ovaleOptions.db.profile.source)) {
this.ovaleOptions.db.profile.source = {};
}
for (let i = 1; i < countSpecializations; i += 1) {
for (let i = 1; i <= countSpecializations; i += 1) {
const specName = this.ovalePaperDoll.getSpecialization(
i as SpecializationIndex
);
Expand Down
2 changes: 1 addition & 1 deletion src/simulationcraft/text-tools.ts
Expand Up @@ -36,7 +36,7 @@ export function printRepeat(data: any) {

function _repeat(str: string, num: number) {
let output = "";
for (let i = 0; i < num; i += 1) {
for (let i = 1; i <= num; i += 1) {
output = output + str;
}
return output;
Expand Down

0 comments on commit 2e7a5ae

Please sign in to comment.