<feed xmlns='http://www.w3.org/2005/Atom'>
<title>unit.git/src, branch archive/cppcheck-fixes</title>
<subtitle>Universal Web Application Server</subtitle>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/'/>
<entry>
<title>HTTP: removed unused nxt_http_cookie_t structure.</title>
<updated>2022-07-18T11:45:28+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-15T19:42:02+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=8cf9ef348eb6190831e3c4a4ccd087e2ac1b8f4d'/>
<id>8cf9ef348eb6190831e3c4a4ccd087e2ac1b8f4d</id>
<content type='text'>
Turns out that struct nxt_http_cookie_t is completely unused.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Turns out that struct nxt_http_cookie_t is completely unused.
</pre>
</div>
</content>
</entry>
<entry>
<title>Router: removed unused structure member proxy_buffers.</title>
<updated>2022-07-18T11:45:28+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-05-05T00:19:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=d22a3242315662f4b7f3332ea01de0cdc67a838a'/>
<id>d22a3242315662f4b7f3332ea01de0cdc67a838a</id>
<content type='text'>
proxy_buffers is declared as a structure member of nxt_socket_conf_t and
is set in nxt_router_conf_create(), however it is not used anywhere.

Removing it has the nice side effect of making the nxt_socket_conf_t
structure require one less cacheline (on x86-64 at least w/out TLS
support) as the summary from pahole[0] shows

    $ pahole -C nxt_socket_conf_t build/unitd

Before

    /* size: 200, cachelines: 4, members: 25 */
    /* sum members: 185, holes: 3, sum holes: 15 */

After

    /* size: 192, cachelines: 3, members: 24 */
    /* sum members: 177, holes: 3, sum holes: 15 */

[0]: https://github.com/acmel/dwarves
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
proxy_buffers is declared as a structure member of nxt_socket_conf_t and
is set in nxt_router_conf_create(), however it is not used anywhere.

Removing it has the nice side effect of making the nxt_socket_conf_t
structure require one less cacheline (on x86-64 at least w/out TLS
support) as the summary from pahole[0] shows

    $ pahole -C nxt_socket_conf_t build/unitd

Before

    /* size: 200, cachelines: 4, members: 25 */
    /* sum members: 185, holes: 3, sum holes: 15 */

After

    /* size: 192, cachelines: 3, members: 24 */
    /* sum members: 177, holes: 3, sum holes: 15 */

[0]: https://github.com/acmel/dwarves
</pre>
</div>
</content>
</entry>
<entry>
<title>Router: avoided undefined behaviour.</title>
<updated>2022-07-18T11:45:06+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-15T15:20:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=58f78932716522bf47dbc185bd7e058dd7c2c7bb'/>
<id>58f78932716522bf47dbc185bd7e058dd7c2c7bb</id>
<content type='text'>
In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there
was potentially undefined behaviour when shifting a 32 bit value by 32
bits, this could happen if cidr_prefix was 0.

Promote the shiftee to unsigned long long to avoid this issue.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there
was potentially undefined behaviour when shifting a 32 bit value by 32
bits, this could happen if cidr_prefix was 0.

Promote the shiftee to unsigned long long to avoid this issue.
</pre>
</div>
</content>
</entry>
<entry>
<title>Port: removed useless msg-&gt;cancelled == 0 checks.</title>
<updated>2022-06-23T18:51:46+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-14T16:14:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=1a5288a9e2bf83414d601ca5e086eedeef164da4'/>
<id>1a5288a9e2bf83414d601ca5e086eedeef164da4</id>
<content type='text'>
In src/nxt_port_socket.c::nxt_port_read_msg_process() msg-&gt;cancelled is
set to 0 and is not touched again.

However there are several checks for it being == 0 which are _always_
true, so remove them.

I'm assuming that this is functioning as intended and that setting
msg-&gt;cancelled to 0 is correct.

msg-&gt;cancelled was set to 0 unconditionally in commit e227fc9
("Introducing application and port shared memory queues."), so I guess
the now redundant checks were simply missed for removal.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In src/nxt_port_socket.c::nxt_port_read_msg_process() msg-&gt;cancelled is
set to 0 and is not touched again.

However there are several checks for it being == 0 which are _always_
true, so remove them.

I'm assuming that this is functioning as intended and that setting
msg-&gt;cancelled to 0 is correct.

msg-&gt;cancelled was set to 0 unconditionally in commit e227fc9
("Introducing application and port shared memory queues."), so I guess
the now redundant checks were simply missed for removal.
</pre>
</div>
</content>
</entry>
<entry>
<title>Unit: removed a useless assignment.</title>
<updated>2022-06-21T22:53:53+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-16T01:01:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=63667e2f9c571ad4357a30e42b321bec6a97ee89'/>
<id>63667e2f9c571ad4357a30e42b321bec6a97ee89</id>
<content type='text'>
As was pointed out by the cppcheck[0] static code analysis utility there
was a useless assignment in nxt_unit_request_read(). The size parameter
is passed in by value and was being modified without being used again.

[0]: https://cppcheck.sourceforge.io/
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As was pointed out by the cppcheck[0] static code analysis utility there
was a useless assignment in nxt_unit_request_read(). The size parameter
is passed in by value and was being modified without being used again.

[0]: https://cppcheck.sourceforge.io/
</pre>
</div>
</content>
</entry>
<entry>
<title>Unit: avoided needlessly setting lib in nxt_unit_shm_open().</title>
<updated>2022-06-21T22:30:44+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-16T01:00:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=39819143ea891b752e5f1f6c6101d0861fb18850'/>
<id>39819143ea891b752e5f1f6c6101d0861fb18850</id>
<content type='text'>
As was pointed out by the cppcheck[0] static code analysis utility, lib
was being set in nxt_unit_shm_open() regardless of platform when in fact
it's only used when (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN).

Move the variable declaration &amp; definition to be within the

  #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN)

block.

[0]: https://cppcheck.sourceforge.io/
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As was pointed out by the cppcheck[0] static code analysis utility, lib
was being set in nxt_unit_shm_open() regardless of platform when in fact
it's only used when (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN).

Move the variable declaration &amp; definition to be within the

  #if (NXT_HAVE_MEMFD_CREATE || NXT_HAVE_SHM_OPEN)

block.

[0]: https://cppcheck.sourceforge.io/
</pre>
</div>
</content>
</entry>
<entry>
<title>Socket: removed useless port &lt; 1 check.</title>
<updated>2022-06-21T22:30:44+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-16T01:00:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=7a286ec0797df4530eeee6f463ae00b86463084b'/>
<id>7a286ec0797df4530eeee6f463ae00b86463084b</id>
<content type='text'>
In src/nxt_sockaddr.c::nxt_job_sockaddr_inet_parse() there is a check
that port &gt; 0 then there is a check that port &lt; 1 || port &gt; 65535, well
we _know_ it can't be less than 1.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In src/nxt_sockaddr.c::nxt_job_sockaddr_inet_parse() there is a check
that port &gt; 0 then there is a check that port &lt; 1 || port &gt; 65535, well
we _know_ it can't be less than 1.
</pre>
</div>
</content>
</entry>
<entry>
<title>Marked a couple of variables 'const'.</title>
<updated>2022-06-21T22:30:44+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-16T01:00:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=29c72085262073dc5dec1ecbde1d520da9763746'/>
<id>29c72085262073dc5dec1ecbde1d520da9763746</id>
<content type='text'>
As was pointed out by the cppcheck[0] static code analysis utility we
can mark a couple of variables as 'const'. This acts as a hint to the
compiler about our intentions and the compiler will tell us when we
deviate from them.

[0]: https://cppcheck.sourceforge.io/
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As was pointed out by the cppcheck[0] static code analysis utility we
can mark a couple of variables as 'const'. This acts as a hint to the
compiler about our intentions and the compiler will tell us when we
deviate from them.

[0]: https://cppcheck.sourceforge.io/
</pre>
</div>
</content>
</entry>
<entry>
<title>Constified numerous function parameters.</title>
<updated>2022-06-21T22:30:44+00:00</updated>
<author>
<name>Andrew Clayton</name>
<email>andrew@digital-domain.net</email>
</author>
<published>2022-06-16T01:00:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=4418f99cd46b17be893b6bd0df56434078e5aad3'/>
<id>4418f99cd46b17be893b6bd0df56434078e5aad3</id>
<content type='text'>
As was pointed out by the cppcheck[0] static code analysis utility we
can mark numerous function parameters as 'const'. This acts as a hint to
the compiler about our intentions and the compiler will tell us when we
deviate from them.

[0]: https://cppcheck.sourceforge.io/
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As was pointed out by the cppcheck[0] static code analysis utility we
can mark numerous function parameters as 'const'. This acts as a hint to
the compiler about our intentions and the compiler will tell us when we
deviate from them.

[0]: https://cppcheck.sourceforge.io/
</pre>
</div>
</content>
</entry>
<entry>
<title>Static: Fixed finding the file extension.</title>
<updated>2022-06-21T10:47:01+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx.manpages@gmail.com</email>
</author>
<published>2022-06-06T12:18:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=c3e40ae932f0cf9ae33166479049d2d3c9fa1615'/>
<id>c3e40ae932f0cf9ae33166479049d2d3c9fa1615</id>
<content type='text'>
The code for finding the extension made a few assumptions that are
no longer true.  It didn't account for pathnames that didn't
contain '/', including the empty string, or the NULL string.  That
code was used with "share", which always had a '/', but now it's
also used with "index", which should not have a '/' in it.

This fix works by limiting the search to the beginning of the
string, so that if no '/' is found in it, it doesn't continue
searching before the beginning of the string.

This also happens to work for NULL.  It is technically Undefined
Behavior, as we rely on `NULL + 0 == NULL` and `NULL - NULL == 0`.
But that is the only sane behavior for an implementation, and all
existing POSIX implementations will Just Work for this code.

Relying on this UB is useful, because we don't need to add an
explicit check for NULL, and therefore we have faster code.
Although the current code can't have a NULL, I expect that when we
add support for variables in the index, it will be NULL in some
cases.

Link: &lt;https://stackoverflow.com/q/67291052/6872717&gt;

The same code seems to be defined behavior in C++, which normally
will share implementation in the compiler for these cases, and
therefore it is really unlikely to be in trouble.

Link: &lt;https://stackoverflow.com/q/59409034/6872717&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The code for finding the extension made a few assumptions that are
no longer true.  It didn't account for pathnames that didn't
contain '/', including the empty string, or the NULL string.  That
code was used with "share", which always had a '/', but now it's
also used with "index", which should not have a '/' in it.

This fix works by limiting the search to the beginning of the
string, so that if no '/' is found in it, it doesn't continue
searching before the beginning of the string.

This also happens to work for NULL.  It is technically Undefined
Behavior, as we rely on `NULL + 0 == NULL` and `NULL - NULL == 0`.
But that is the only sane behavior for an implementation, and all
existing POSIX implementations will Just Work for this code.

Relying on this UB is useful, because we don't need to add an
explicit check for NULL, and therefore we have faster code.
Although the current code can't have a NULL, I expect that when we
add support for variables in the index, it will be NULL in some
cases.

Link: &lt;https://stackoverflow.com/q/67291052/6872717&gt;

The same code seems to be defined behavior in C++, which normally
will share implementation in the compiler for these cases, and
therefore it is really unlikely to be in trouble.

Link: &lt;https://stackoverflow.com/q/59409034/6872717&gt;
</pre>
</div>
</content>
</entry>
</feed>
