Date: Mon, 24 Mar 2025 16:59:20 +0100 From: Olivier Certner <olce@freebsd.org> To: Konstantin Belousov <kib@freebsd.org>, Ronald Klop <ronald-lists@klop.ws> Cc: dev-commits-src-all@freebsd.org, src-committers@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: c18a16ebcf5b - main - kern_proc_kqueues_out(): maxlen == -1 means there is no maxlen Message-ID: <8229058.iDzAj6rjnq@ravel> In-Reply-To: <1305725331.9507.1742828788168@localhost> References: <202503240454.52O4s0Xi051381@gitrepo.freebsd.org> <1305725331.9507.1742828788168@localhost>
next in thread | previous in thread | raw e-mail | index | archive | help
--nextPart2149079.x0N0T6uNKo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8"; protected-headers="v1" From: Olivier Certner <olce@freebsd.org> Date: Mon, 24 Mar 2025 16:59:20 +0100 Message-ID: <8229058.iDzAj6rjnq@ravel> In-Reply-To: <1305725331.9507.1742828788168@localhost> MIME-Version: 1.0 Hi, > (snip) =20 > > + if (maxlen =3D=3D -1 || maxlen =3D=3D 0) > As maxlen is of the unsigned type size_t, how can it be -1? > Or am I mistaken on this? It's of course true that 'maxlen' can't be -1 mathematically as it has an u= nsigned type, but that's not what 'maxlen =3D=3D -1' tests. In this exampl= e, 'maxlen' is an unsigned type of size at least equal to 'unsigned int', w= hose values cannot all be represented in a signed 'int' (well, that last pa= rt is true but not the real reason, which has to do with integer ranks). A= ccording to the standard promotion rules, and because -1 as an integer cons= tant is interpreted as of type 'int', both arguments of '=3D=3D' will be co= nverted to 'unsigned int', and conversion of a signed type to an unsigned o= ne is done by computing its congruence to the number of values the latter c= an represent (this is the mathematical description; with two-complement rep= resentation, that's basically just truncating the bits that are "too high",= or sign-extending if the unsigned type destination is wider, and in this p= recise case, just keeping the same exact representation bits). So, basicall= y, this test is equivalent to 'maxlen =3D=3D UINT_MAX' on 32-bit machines o= r 'maxlen =3D=3D ULONG_MAX' on 64-bit ones. Relevant C standard passages are, in section Language > Conversions > Arith= metic operands, the "Boolean, characters, and integers", "Signed and unsign= ed integers" and "Usual arithmetic conversions" chapters, and, under Langua= ge > Expressions, the chapter about equality operators (in particular, the = fact that it states that the usual arithmetic conversions apply), and chapt= er Language > Lexical elements > Constants > Integer constants. Regards. =2D-=20 Olivier Certner --nextPart2149079.x0N0T6uNKo Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQIzBAABCQAdFiEEmNCxHjkosai0LYIujKEwQJceJicFAmfhgVgACgkQjKEwQJce JicMug/8DXuApknJ9/MpLLBj6QZ3TICmietYFg3OYjHGVkluxu9nmRoSDlre3Het d/9csBgriOiW8MJHgkq9FiJsmq6kwvLdh3cEeUjcdwGWdqapY7+gm5h1K3I9Pm3O hW3dJne9lJL1aSlbz189QdA70aCf3+Mu91d1pVGVtzctXman7nkDUI1l6JTri3hu 0VOD/FsirlOt6JWSyVGuYRbMRCR7ViaGks9ahjo9aRyV1wCmUCaysG1JevvYyDLh o14vECCOPZltsuDA8XbV9uDjCon4KR0wTL2nFNwAPTI0DnobQ8Y2ntGcuJdBP1p0 r0ZWNjFrCOsxutpep2N6ODaiIhXMrKcsD6VPgSLcOcd4oCYvf60EgkCQiE5HG+HQ 7JrLfVvldqo4oXNJtzlXRTe8ODZ37gd6mFZtiJ611fA9pZ23ZFWy4aQ/1iWLyFEN S7lvBo9Pbyi/qhD8SHvMDrZraP3DpD+HDzJDmoAs5Z4MtGO02YSX7eZ6LLeoq4Pw /y7rrj/AdyDfAopseR5go0tPr3Mw1ToRH8HPsL0igluKuQ8vX/6lcve97Z4K+6D1 IFFooTh7OvCjb/R5o0w2ScNJsuKBBeHafadd2I7zg1Z5ih7QD8PHQCiKhKByOF+4 nG/gaSrGiqsmOkSfKSUbfJrmLFX7aOf7oF6rmvZeZEuvRLg3qVs= =V36y -----END PGP SIGNATURE----- --nextPart2149079.x0N0T6uNKo--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?8229058.iDzAj6rjnq>