description | CLI utility to swap consecutive hex digits (nibbles) in a string |
owner | alessio.chiapperini@nullbuffer.com |
last change | Tue, 28 May 2024 10:04:58 +0000 (28 12:04 +0200) |
URL | git://repo.or.cz/nibswap.git |
https://repo.or.cz/nibswap.git | |
push URL | ssh://repo.or.cz/nibswap.git |
https://repo.or.cz/nibswap.git (learn more) | |
bundle info | nibswap.git downloadable bundles |
content tags |
The nibswap utility swaps consecutive hex digits (nibbles) in a string.
scan-build
using checkers alpha.security
, alpha.core.CastSize
,
alpha.core.CastToStruct
, alpha.core.IdenticalExpr
, alpha.core.PointerArithm
, alpha.core.PointerSub
,
alpha.core.SizeofPtr
, alpha.core.TestAfterDivZero
, alpha.unix
.LINE_MAX
bytes in length.The only dependency is a toolchain supporting the following flags:
CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic \
-Walloca -Wcast-qual -Wconversion -Wformat=2 -Wformat-security \
-Wnull-dereference -Wstack-protector -Wvla -Warray-bounds \
-Wbad-function-cast -Wconversion -Wshadow -Wstrict-overflow=4 -Wundef \
-Wstrict-prototypes -Wswitch-default -Wfloat-equal -Wimplicit-fallthrough \
-Wpointer-arith -Wswitch-enum \
-D_FORTIFY_SOURCE=2 \
-fstack-protector-strong -fPIE -fstack-clash-protection
LDFLAGS = -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,-z,separate-code
Otherwise you can just remove the security flags and compile it with
CFLAGS = -std=c99 -O2 -Wall -Wextra -Wpedantic
LDFLAGS =
or pass your own flags to make
make CC=gcc CFLAGS=... LDFLAGS=...
Clone this repository then
$ make PREFIX=/usr install
This will install the compiled binary under PREFIX
(/usr/bin
) in this case, if not specified PREFIX
will default
to /usr/local
. For staged installs, DESTDIR
is also supported. As the binary does not have any dependency it does
not have to be installed before use.
nibswap receives as input one or more files. The files however, can be omitted, in this case the program takes
the input from the standard input until EOF
or ^D
is reached. If a file is a single dash (‘-’), nibswap reads
from standard input.
The options are as follows:
$ nibswap
A1B2C3
1A2B3C
$ cat strings
A1B2C3
1A2B3C4D
$ nibswap strings
1A2B3C
A1B2C3D4
The test suite consists of a POSIX shell script called harness.sh
contained in the test
folder. It's output is
similar to googletest's and it can be invoked with make test
which, if
everything is working should output something similar to
(cd test && ./harness.sh)
[----------] Test environment set-up.
[==========] Running 7 test cases.
[ RUN ] should_handle_stdin
[ OK ] should_handle_stdin
[ RUN ] should_handle_one_file
[ OK ] should_handle_one_file
[ RUN ] should_handle_two_files
[ OK ] should_handle_two_files
[ RUN ] should_handle_dash
[ OK ] should_handle_dash
[ RUN ] should_refuse_odd_length_string
nibswap: the length of the string 'A1B2C' must be even
[ OK ] should_refuse_odd_length_string
[ RUN ] should_handle_empty_string
[ OK ] should_handle_empty_string
[ RUN ] should_handle_long_string
[ OK ] should_handle_long_string
[==========] 7 test cases ran.
[ PASSED ] 7 tests.
[ FAILED ] 0 tests.
[----------] Test environment teardown.
Static analysis on the code base is done by using clang's static analyzer run through scan-build.sh
which wraps the
scan-build
utility. The checkers used are part of the
Experimental Checkers
(aka alpha checkers):
alpha.security
alpha.core.CastSize
alpha.core.CastToStruct
alpha.core.IdenticalExpr
alpha.core.PointerArithm
alpha.core.PointerSub
alpha.core.SizeofPtr
alpha.core.TestAfterDivZero
alpha.unix
BSD 2-Clause FreeBSD License, see LICENSE.
2024-05-28 | Alessio Chiapperini | Explicitly write out inference rule for .c.omaster | commitcommitdifftreesnapshot (tar.gz zip) |
2022-12-09 | Alessio Chiapperini | Suppress error during test | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-10 | Alessio Chiapperini | Move const qualifier at the beginning | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-10 | Alessio Chiapperini | Remove quotes from modulo computation | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-09 | Alessio Chiapperini | Update README | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-08 | Alessio Chiapperini | Update README | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-08 | Alessio Chiapperini | Add long string test case | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-07 | Alessio Chiapperini | Update README.md and manpage | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-07 | Alessio Chiapperini | Add everything | commitcommitdifftreesnapshot (tar.gz zip) |
2022-10-07 | Alessio Chiapperini | Add empty README.md | commitcommitdifftreesnapshot (tar.gz zip) |
3 months ago | master | logtree |