Module Name: src
Committed By: mrg
Date: Thu Mar 14 00:00:31 UTC 2024
Modified Files:
src/usr.bin/audio/common: wav.c
Log Message:
fix some sizeof() confusion.
using "const char search[4]" as a function parameter means that
"search" is actually a pointer type so "sizeof search" returns
8 on 64-bit platforms. i mis-read this and used "sizeof *search"
which is always 1, noted by rillig.
instead of trying to avoid writing "4" twice, put it in a define
and use that in various places instead. annoying.
To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/audio/common/wav.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/audio/common/wav.c
diff -u src/usr.bin/audio/common/wav.c:1.22 src/usr.bin/audio/common/wav.c:1.23
--- src/usr.bin/audio/common/wav.c:1.22 Tue Mar 12 00:34:38 2024
+++ src/usr.bin/audio/common/wav.c Thu Mar 14 00:00:31 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: wav.c,v 1.22 2024/03/12 00:34:38 mrg Exp $ */
+/* $NetBSD: wav.c,v 1.23 2024/03/14 00:00:31 mrg Exp $ */
/*
* Copyright (c) 2002, 2009, 2013, 2015, 2019, 2024 Matthew R. Green
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: wav.c,v 1.22 2024/03/12 00:34:38 mrg Exp $");
+__RCSID("$NetBSD: wav.c,v 1.23 2024/03/14 00:00:31 mrg Exp $");
#endif
@@ -91,8 +91,10 @@ wav_enc_from_val(int encoding)
* WAV format helpers
*/
+#define RIFFNAMELEN 4
+
static bool
-find_riff_chunk(const char search[4], size_t *remainp, char **wherep, uint32_t *partlen)
+find_riff_chunk(const char *search, size_t *remainp, char **wherep, uint32_t *partlen)
{
wav_audioheaderpart part;
@@ -116,7 +118,7 @@ find_riff_chunk(const char search[4], si
emsg = " (odd length, adjusted)";
len += 1;
}
- if (strncmp(part.name, search, sizeof *search) == 0) {
+ if (strncmp(part.name, search, RIFFNAMELEN) == 0) {
*partlen = len;
if (verbose > 1)
fprintf(stderr, "Found part %.04s length %d%s\n",
@@ -148,10 +150,10 @@ audio_wav_parse_hdr(void *hdr, size_t sz
uint32_t len = 0;
u_int16_t fmttag;
static const char
- strfmt[4] = "fmt ",
- strRIFF[4] = "RIFF",
- strWAVE[4] = "WAVE",
- strdata[4] = "data";
+ strfmt[RIFFNAMELEN] = "fmt ",
+ strRIFF[RIFFNAMELEN] = "RIFF",
+ strWAVE[RIFFNAMELEN] = "WAVE",
+ strdata[RIFFNAMELEN] = "data";
bool found;
if (sz < 32)