mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Cc: "jounijl@yahoo.co.uk" <jounijl@yahoo.co.uk>
Subject: Re: "Arithmetic exception" with modulus operator '%'
Date: Fri, 15 Feb 2019 11:05:27 +0100	[thread overview]
Message-ID: <20190215100527.GT21289@port70.net> (raw)
In-Reply-To: <a1b6f88d-a0c1-5dad-aecd-98394573574e@yahoo.co.uk>

* jounijl@yahoo.co.uk <jounijl@yahoo.co.uk> [2019-02-15 03:35:23 +0000]:
> 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

undefined behaviour == anything can happen

the compiler can drop this entirely.

> ----- /snip -----
> 
> The variables have some values other than 0.
> 
> The environment is:
> The Alpine Linux is installed in Oracle Virtualbox in FreeBSD 12, 64-bit
> Intel.

x86_64 traps mod by 0 (in case the compiler didn't
drop the code path because of ub).

> 
> $ uname -a
> Linux localhost 4.14.89-0-vanilla #1-Alpine SMP Tue Dec 18 16:10:10 UTC 2018
> x86_64 GNU/Linux
> 
> $ clang --version
> Alpine clang version 5.0.1 (tags/RELEASE_501/final) (based on LLVM 5.0.1)
> 
> What does this? Do I need to include some library?

what behaviour do you expect?

> 
> w.b.reg., Jouni


      parent reply	other threads:[~2019-02-15 10:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-15  3:35 jounijl
2019-02-14 23:58 ` Rich Felker
2019-02-15 10:31   ` jounijl
2019-02-15 17:21     ` Rich Felker
2019-02-15 10:05 ` Szabolcs Nagy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190215100527.GT21289@port70.net \
    --to=nsz@port70.net \
    --cc=jounijl@yahoo.co.uk \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).