← Commit list

1113961dd

Denys Vlasenko
Denys Vlasenko
2019-05-16
SUCCESS Duration: 153s

Subject

dc: make 4 % 0 emit error messgaes and set result to 0

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

miscutils/dc.c+12 -7
@@ -94,13 +94,18 @@ static void mod(void)
{
data_t d = pop();
- //if (d == 0) {
- // bb_error_msg("remainder by zero");
- // pop();
- // push(0);
- // return;
- //}
- //^^^^ without this, we simply get SIGFPE and die
+ /* compat with dc (GNU bc 1.07.1) 1.4.1:
+ * $ dc -e '4 0 % p'
+ * dc: remainder by zero
+ * 0
+ */
+ if (d == 0) {
+ bb_error_msg("remainder by zero");
+ pop();
+ push(0);
+ return;
+ }
+ /* ^^^^ without this, we simply get SIGFPE and die */
push((data_t) pop() % d);
}