Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuspiciousMessageMode: Don't report 0 #199

Merged
merged 17 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- `ShortCircuitCondition` detector: PR [#202](https://github.com/nowarp/misti/pull/202)

### Changed
- `SuspiciousMessageMode` detector now suggests using SendDefaultMode instead of 0 for mode: PR [#199](https://github.com/nowarp/misti/pull/199/)
jubnzv marked this conversation as resolved.
Show resolved Hide resolved
## [0.5.0] - 2024-10-31

### Added
Expand Down
14 changes: 14 additions & 0 deletions src/detectors/builtin/suspiciousMessageMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ export class SuspiciousMessageMode extends ASTDetector {
expr: AstExpression,
warnings: MistiTactWarning[],
): void {
if (expr.kind === "number" && expr.value === 0n) {
warnings.push(
jubnzv marked this conversation as resolved.
Show resolved Hide resolved
this.makeWarning(
"Setting `mode` to `0` is redundant as it has no effect.",
expr.loc,
{
suggestion:
"Remove the `mode` field or set it to `SendDefaultMode`.",
},
),
);
return;
}

const flagsUsed = new Set<string>();
forEachExpression(expr, (e) => {
switch (e.kind) {
Expand Down
9 changes: 9 additions & 0 deletions test/detectors/SuspiciousMessageMode.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ test/detectors/SuspiciousMessageMode.tact:61:21:
^
62 | });
Help: Use the '|' operator (bitwise OR) to combine flags
See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode

[MEDIUM] SuspiciousMessageMode: Setting `mode` to `0` is redundant as it has no effect.
test/detectors/SuspiciousMessageMode.tact:79:15:
78 | value: 0,
> 79 | mode: 0 // Bad: Should trigger warning about `mode: 0` being redundant
^
80 | });
Help: Remove the `mode` field or set it to `SendDefaultMode`.
See: https://nowarp.io/tools/misti/docs/detectors/SuspiciousMessageMode
8 changes: 8 additions & 0 deletions test/detectors/SuspiciousMessageMode.tact
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,12 @@ contract SendParametersTestContract {
mode: modeFlag // Ok
});
}

fun modeZeroUsage() {
send(SendParameters{
to: sender(),
value: 0,
mode: 0 // Bad: Should trigger warning about `mode: 0` being redundant
});
}
}
Loading