mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jon Scobie <jon.scobie@callsign.com>
To: musl@lists.openwall.com
Subject: Re: Maybe not a bug but a possible omission?
Date: Wed, 28 Mar 2018 14:33:23 +0100	[thread overview]
Message-ID: <CACxTtGu8eakWLOoV2WV4Tb3+jcrQLux6_HmmCNL0hRY6yDDs_A@mail.gmail.com> (raw)
In-Reply-To: <B20288AA-50AB-4C6D-AF96-B626FCB065CD@hanauska.name>


[-- Attachment #1.1: Type: text/plain, Size: 4447 bytes --]

Well, I definitely agree that instead of definitions like

#define INT64_MIN  (-1-0x7fffffffffffffff)

we should have

#define INT64_MIN  (-1 - INT64_C(0x7fffffffffffffff))


As for the WCHAR_MAX|MIN definitions, yes, swig should handle those. I'll
check the source and see about a patch for submission.

If the definitions above are what should be used, how do I go about getting
those updated?

Regards,
Jon.


*JON SCOBIE*
SENIOR SECURITY ENGINEER

+44 7894253988 <+44%7894253988>


www.callsign.com


On 28 March 2018 at 13:52, CodingMarkus <CodingMarkus@hanauska.name> wrote:

>
>
> > On 2018-03-28, at 12:31, Jon Scobie <jon.scobie@callsign.com> wrote:
> >
> > #define INT64_MIN  (-1-0x7fffffffffffffff)
> >
> > the equivalent glibc definition is the equivalent of
> >
> > #define INT64_MIN  (-1-0x7fffffffffffffffL)
>
> According to ISO-C 2011 standard (page 63):
>
> "The type of an integer constant is the first of the corresponding list in
> which its value can be represented.”
>
> And for constants that have no type suffix (no “L”, “LL”, “U”, “UL”,
> “ULL”), the “list” mentioned above contains the following types decimal
> values:
>
> int, long int, long long int
>
> and the following types of octal/hex values:
>
> int, unsigned int, long int, unsigned long int, long long int, unsigned
> long long int
>
> Thus the type is the first one of the three above that is big enough to
> represent a constant value.
>
> By using the suffix “L”, all that happens is that the type list is further
> limited down to:
>
> long int, long long int
>
> or for octal/hex values:
>
> long int, unsigned long int, long long int, unsigned long long int
>
> On most systems, only long int or long long int can represent
> "(-1-0x7fffffffffffffff)”, so either one will be the deferred type.
> Appending the suffix “L” would thus not make any difference, as it will not
> result in a different type. It only eliminates the type “int” from the list
> but I don’t know any system where the type int could represent such a big
> number, so int is never chosen to begin with.
>
> Personally I wonder about that definition in both libraries, I had
> expected it to be:
>
> #define INT64_MIN  INT64_C(...)
>
> because that assures the type is pinned to whatever type int64_t maps on
> the system. After all the C standard also says about INT64_MIN the other
> defines:
>
> "Each instance of any defined macro shall be replaced by a constant
> expression suitable for use in #if preprocessing directives, and this
> expression shall have the same type as would an expression that is an
> object of the corresponding type converted according to the integer
> promotions.”
>
> So INT64_MIN should be the same type as int64_t is (that’s how I interpret
> the last part of that sentence) and that is not always guaranteed when
> defined as above, as when defined as above, a long int is enough to
> represent that type on a 64 bit system (on 64 bit systems, long is
> typically 64 bit already), whereas int64_t may as well be a long long int
> on such a system. At least PRI64d typically uses “lld” AFAIK and not “ld”,
> though I have not checked what musl or glibc uses for PRI64d on 64 bit
> systems.
>
> > The issue is that swig has no idea what type INT64_MAX is if you don't
> specifically state what it is so it treats it as a goint - which is not a
> long (or long long).
>
> If swig fails to correctly process valid C code, then this sounds like a
> bug that the swig developers should really fix. The type of a numeric
> constant is always exactly defined by the C standard, it’s never required
> to give an explicit type unless you want a “wider” type than would have
> been chosen automatically otherwise or you want to force a signed value to
> be an unsigned type. Every tool parsing, compiling or processing C code
> should know the type rules and should apply them the same way a C compiler
> would do it, shouldn’t it?
>
> Regards,
> Markus
>
>

-- 

----
The information contained in this communication is private and confidential 
and may contain privileged material. It is intended solely for use by the 
recipient(s). Copying, distributing, disclosing or using any of the 
information in it or any attachments is strictly prohibited and may be 
unlawful.

[-- Attachment #1.2: Type: text/html, Size: 7315 bytes --]

[-- Attachment #2: logo-green.png --]
[-- Type: image/png, Size: 1566 bytes --]

  reply	other threads:[~2018-03-28 13:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 10:31 Jon Scobie
2018-03-28 12:52 ` CodingMarkus
2018-03-28 13:33   ` Jon Scobie [this message]
2018-03-28 17:19     ` Szabolcs Nagy
2018-03-28 17:54       ` Rich Felker
2018-03-29  0:30         ` Jon Scobie
2018-03-29  4:53           ` Markus Wichmann

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=CACxTtGu8eakWLOoV2WV4Tb3+jcrQLux6_HmmCNL0hRY6yDDs_A@mail.gmail.com \
    --to=jon.scobie@callsign.com \
    --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).