Skip to content

Commit 10e631d

Browse files
committed
Command: add “floatinvalid” and “floatoverflow” to injectFault command, also fix “floatdiv”
1 parent 9735af9 commit 10e631d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/common/Command.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ class InjectFaultCmd : public Cmd::StaticCmd
542542
.detach();
543543
} else {
544544
if (!DoFault(args)) {
545-
Print("Usage: %s (drop | error | segfault | intdiv | floatdiv | unreachable"
546-
" | exception | throw | terminate | abort | freeze <seconds>) [thread]",
545+
Print("Usage: %s (drop | error | segfault | intdiv | floatinvalid | floatdiv | floatoverflow"
546+
" | unreachable | exception | throw | terminate | abort | freeze <seconds>) [thread]",
547547
args.Argv(0));
548548
}
549549
}
@@ -573,9 +573,15 @@ class InjectFaultCmd : public Cmd::StaticCmd
573573
} else if (how == "intdiv") {
574574
volatile int n = 0;
575575
n = n / n;
576+
} else if (how == "floatinvalid") {
577+
volatile float f = -1.0f;
578+
f = sqrtf(f);
576579
} else if (how == "floatdiv") {
577-
volatile float x = 0;
578-
x = x / x;
580+
volatile float f = 0;
581+
f = 1 / f;
582+
} else if (how == "floatoverflow") {
583+
volatile float f = std::numeric_limits<float>::max();
584+
f = 2 * f;
579585
} else if (how == "unreachable") { // May print the usage string :)
580586
UNREACHABLE();
581587
} else if (how == "exception") { // std::exception

0 commit comments

Comments
 (0)