commit 69bc8857232cddda7bbae5926ccaff036d32d282
parent 7c0fa84fb010bb73397cc45bb085451908717ecc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sat, 16 Mar 2024 19:01:38 +0100
Fixed warnings when WAD file starts with null bytes
A "null byte ignored in input" warning was displayed when following a
WAD file containing null bytes in the header. We tried to copy them into
a variable, but variables can't store null bytes. Hence the warning. So
we replace them with a 0 when copying. And that's no problem, since the
header string we're looking for contains neither null bytes nor 0. In
any case, the copied bytes will therefore be ignored as expected.
Diffstat:
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/git-wad b/git-wad
@@ -234,8 +234,17 @@ clean() # stdin
digest=$(cat - | tee "${tmpfile}" | sha256sum | cut -d' ' -f1)
size=$(wc -c < "${tmpfile}")
+ # Copy all bytes that could correspond to a WAD header. Note that null
+ # bytes are replaced by a 0 to avoid a warning about ignored null
+ # bytes: they cannot be stored in a variable. Replacing them is not a
+ # problem, since the header string you're looking for doesn't contain
+ # any. You just have to be careful not to replace them with a
+ # character belonging to the WAD header, which could lead to random
+ # bytes being mistakenly translated into a WAD header, as searched for
+ # in the following.
header_size="$(sizeof_header)"
- header="$(dd ibs=1 count="${header_size}" < "${tmpfile}" 2> /dev/null)"
+ header="$(dd ibs=1 count="${header_size}" if="${tmpfile}" 2>/dev/null\
+ | tr '\0' '0')"
# Do not clean input stream if it is an un-smudged WAD
if [ "${header}" = "${GIT_WAD_HEADER}" ]; then
@@ -264,7 +273,7 @@ clean() # stdin
smudge() # stdin
{
header_size="$(sizeof_header)"
- header="$(dd ibs=1 count="${header_size}" 2> /dev/null)"
+ header="$(dd ibs=1 count="${header_size}" 2> /dev/null | tr '\0' '0')"
if [ "${header}" != "${GIT_WAD_HEADER}" ]; then # It is not a WAD
log "git-wad:filter-smudge: not a managed file"
@@ -377,7 +386,8 @@ status() # [-1a]
wad_paths | while read -r wad; do
# Read the WAD bytes corresponding to its header before it is restored
header_size="$(sizeof_header)"
- header="$(dd if="${wad}" ibs=1 count="${header_size}" 2> /dev/null)"
+ header="$(dd if="${wad}" ibs=1 count="${header_size}" 2> /dev/null \
+ | tr '\0' '0')"
# The header read is not a valid WAD header, i.e. the WAD has
# already been restored