Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 15 Feb 2019 10:31:22 +0000
From: "" <>
To: Rich Felker <>
Subject: Re: "Arithmetic exception" with modulus operator '%'

Exactly. To be complite:

The host machine prints: "Floating point exception" and outputs a core 
file. Uses: /lib/
The Alpine prints: "Arithmetic exception".  Uses: /lib/
Solaris 10 prints: "Arithmetic exception". Uses: /lib/ ; 
Ubuntu prints: "Floating point exception" and outputs a core file. Uses: 

To the question "what do you except":
Of course the behaviour is similar to others and this is correct. As in 
programs the behaviour would be best like this: number%zero would be the 
number it self when number/zero is undefined or infinity (maby set the 
number to the largest known number). To change this, some mathematical 
evaluation would be needed. Answer: mod 0: Convenient would be the 
number it self ?

Maby the core file has to be enabled somehow. Attached is a complite 
test program. The word "trap" is unfamiliar to me. I think it means just 
checking with an 'if'-like comparison.

Thank you for the replies. It helped. The simple facts are not always 


the file:

$ cat m.c
#include <stdio.h>
int    main( int argc, char *argv[] );
int    main( int argc, char *argv[] ){
         unsigned int z = 0;
         unsigned int w = 0;
         //floating point exception: fprintf( stderr, "\n 0 %% 0 = %i", 
(int) z%w );
         z = 1;
         //floating point exception: fprintf( stderr, "\n 1 %% 0 = %i", 
(int) z%w );
         z = 0; w = 1;
         fprintf( stderr, "\n 0 %% 1 = %i", (int) z%w );
         z = 1; w = 1;
         fprintf( stderr, "\n 1 %% 1 = %i", (int) z%w );

On 14.2.2019 23.58, Rich Felker wrote:
> On Fri, Feb 15, 2019 at 03:35:23AM +0000, wrote:
>> As in the headline. Program stops and prints "Arithmetic exception"
>> at the line where the modulus operator '%' is.
>> I'm compiling in Alpine linux with clang installed from apk:s:
>> clang -c test.c
>> clang -o test test.o
>> The code is:
>> ----- snip -----
>>          unsigned int unum  = 0;
>>          unsigned int umod  = 0;
>>          unsigned int ures  = 0;
>>          ures = unum % umod; // <-- this one
>> ----- /snip -----
>> The variables have some values other than 0.
> I don't follow. You say they have some value other than 0, but the
> above example snippet has them as zero, and if they're 0 it's
> undefined behavior and a fault of some sort is a typical result. What
> did you expect to happen?
> Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.