Re: textutils -> od 2.0.14 bug - solved

Jim Meyering <[email protected]>
Newsgroups gmane.comp.gnu.textutils.bugs
Message-ID <[email protected]>
"Eric Backus" <[email protected]> wrote:
...
> I have verified that MS Visual C++ 6.0 produces an error when given the
> above code.  I also verified that gcc 2.95.2 accepts it without any
> warnings, but does produce a warning for it if given the "-pedantic" flag.

Thanks for pointing that out.
Here's an additional patch that fixes that.
Now, the array dimension is +1 or -1.

Index: od.c
===================================================================
RCS file: /fetish/textutils/src/od.c,v
retrieving revision 1.126
diff -u -p -u -p -r1.126 od.c
--- od.c	14 May 2002 21:31:42 -0000	1.126
+++ od.c	22 May 2002 07:14:54 -0000
@@ -153,10 +153,10 @@ static const int width_bytes[] =
 
 /* Ensure that for each member of `enum size_spec' there is an
    initializer in the width_bytes array.  */
-struct assert_width_bytes_matches_size_spec_decl
+struct dummy
 {
-  int t1[sizeof width_bytes / sizeof width_bytes[0] - N_SIZE_SPECS];
-  int t2[N_SIZE_SPECS - sizeof width_bytes / sizeof width_bytes[0]];
+  int assert_width_bytes_matches_size_spec_decl
+    [sizeof width_bytes / sizeof width_bytes[0] == N_SIZE_SPECS ? 1 : -1];
 };
 
 /* Names for some non-printing characters.  */

>> > As an alternative, you could have an N_WIDTH_BYTES entry at the end of
> the
>> > width_bytes array, and then have something like:
>> >
>> > #if N_SIZE_SPECS != N_WIDTH_BYTES
>> > #error Array size mismatch
>> > #endif

That is indeed more readable.  But I don't see how to
get N_WIDTH_BYTES automatically without using sizeof.
If you can make that work, please send a complete patch.

> To force the two arrays to have the same size, I find the above #if
> statement much more straightforward than the
> structure-with-zero-length-arrays anyway.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.