[PATCH 00/11] Various fixes/cleanups

Andrew Clayton andrew at digital-domain.net
Thu Jun 16 01:00:50 UTC 2022


One of my favourite tools is the cppcheck[0] static code analyser.
Running it on the Unit code base threw up numerous items of interest.

These patches cover the following

  - arithOperationsOnVoidPointer

    Array: avoided void pointer arithmetic in nxt_array_copy().

  - constParameter

    Constified numerous function parameters.

  - constVariable

    Marked a couple of variables 'const'.

  - knownConditionTrueFalse

    Port: removed useless msg->cancelled == 0 checks.
    Socket: removed useless port < 1 check.

  - overlappingWriteUnion

    Sptr: avoided potentially undefined behaviour.

  - shiftTooManyBits

    Route: avoided undefined behaviour.

  - unreadVariable

    Unit: avoided needlessly setting lib in nxt_unit_shm_open().

  - unusedStructMember

    HTTP: removed unused nxt_http_cookie_t structure.
    Router: removed unused structure member proxy_buffers.

  - uselessAssignmentArg

    Unit: removed a useless assignment.

I'm posting this patch series to get some initial review/feedback before
opening a pull-request.

All the tests under src/test continue to build and pytest runs
successfully

======================= 91 passed, 687 skipped in 27.35s =======================

Hopefully things are split up enough to ease review and if somethings
are not required, not wanted or just plain wrong they should be easily
dropped.

Andrew

[0]: https://cppcheck.sourceforge.io/

Andrew Clayton (11):
  Array: avoided void pointer arithmetic in nxt_array_copy().
  Constified numerous function parameters.
  Marked a couple of variables 'const'.
  Port: removed useless msg->cancelled == 0 checks.
  Socket: removed useless port < 1 check.
  Sptr: avoided potentially undefined behaviour.
  Route: avoided undefined behaviour.
  Unit: avoided needlessly setting lib in nxt_unit_shm_open().
  Router: removed unused structure member proxy_buffers.
  HTTP: removed unused nxt_http_cookie_t structure.
  Unit: removed a useless assignment.

 src/nxt_array.c            |  2 +-
 src/nxt_conf.c             | 10 +++++-----
 src/nxt_conf.h             |  6 +++---
 src/nxt_http.h             |  5 +++--
 src/nxt_http_parse.c       | 26 +++++++++++++-------------
 src/nxt_http_parse.h       |  2 +-
 src/nxt_http_request.c     | 12 ++++++------
 src/nxt_http_route.c       |  9 ---------
 src/nxt_http_route_addr.c  |  2 +-
 src/nxt_http_static.c      |  4 ++--
 src/nxt_mp.c               |  4 ++--
 src/nxt_port_memory_int.h  |  2 +-
 src/nxt_port_socket.c      | 31 ++++++++++++-------------------
 src/nxt_router.c           |  1 -
 src/nxt_router.h           |  1 -
 src/nxt_sockaddr.c         |  2 +-
 src/nxt_string.c           |  2 +-
 src/nxt_string.h           |  2 +-
 src/nxt_time_parse.c       |  2 +-
 src/nxt_unit.c             | 11 +++++------
 src/nxt_unit_sptr.h        |  5 ++++-
 src/nxt_websocket_accept.c |  4 ++--
 22 files changed, 65 insertions(+), 80 deletions(-)

-- 
2.36.1



More information about the unit mailing list