Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix wrong warning about bitfield i...



details:   https://anonhg.NetBSD.org/src/rev/c57bbd801760
branches:  trunk
changeset: 948832:c57bbd801760
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jan 01 19:11:19 2021 +0000

description:
lint: fix wrong warning about bitfield in C99 structure initialization

The variable namemem is supposed to be a circular list, which is
"documented" implicitly in push_member.

The implementation was buggy though.  In pop_member, the circular list
was destroyed though.  Given the list (capital, major, favorite_color,
green), removing capital made major point to itself in the forward
direction, even though it should not have been modified at all.

In the test, I had been too optimistic to quickly understand the code
around variable initialization.  I was wrong though, so I had to adjust
the comments there to reality.

diffstat:

 tests/usr.bin/xlint/lint1/d_init_pop_member.c   |  10 +++++-----
 tests/usr.bin/xlint/lint1/d_init_pop_member.exp |   2 --
 usr.bin/xlint/lint1/init.c                      |   8 ++++----
 3 files changed, 9 insertions(+), 11 deletions(-)

diffs (74 lines):

diff -r 4921a20f98b3 -r c57bbd801760 tests/usr.bin/xlint/lint1/d_init_pop_member.c
--- a/tests/usr.bin/xlint/lint1/d_init_pop_member.c     Fri Jan 01 17:21:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_pop_member.c     Fri Jan 01 19:11:19 2021 +0000
@@ -1,7 +1,7 @@
 # 2
 
 /*
- * Between init.c 1.27 from 2015-07-28 and init.c 1.52 from 2021-01-01,
+ * Since init.c 1.27 from 2015-07-28,
  * a bug in memberpop or pop_member led to a wrong error message
  * "undefined struct/union member: capital [101]" in the second and third
  * named initializer.
@@ -37,20 +37,20 @@
        struct state st = {
            .capital.major.hobbies.dancing = 1,
            /*
-            * Between 2015-07-28 and 2021-01-01:
+            * Since 2015-07-28:
             * wrong "undefined struct/union member: capital [101]"
             */
            /*
-            * As of 2020-01-01:
+            * Before init.c 1.52 from 2020-01-01:
             * wrong "warning: bit-field initializer does not fit [180]"
             */
            .capital.major.favorite_color.green = 0xFF,
            /*
-            * Between 2015-07-28 and 2021-01-01:
+            * Since 2015-07-28:
             * wrong "undefined struct/union member: capital [101]"
             */
            /*
-            * As of 2020-01-01:
+            * Before init.c 1.52 from 2020-01-01:
             * wrong "warning: bit-field initializer does not fit [180]"
             */
            .capital.major.favorite_color.red = 0xFF
diff -r 4921a20f98b3 -r c57bbd801760 tests/usr.bin/xlint/lint1/d_init_pop_member.exp
--- a/tests/usr.bin/xlint/lint1/d_init_pop_member.exp   Fri Jan 01 17:21:47 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_pop_member.exp   Fri Jan 01 19:11:19 2021 +0000
@@ -1,4 +1,2 @@
 (47): undefined struct/union member: capital [101]
-(47): warning: bit-field initializer does not fit [180]
 (57): undefined struct/union member: capital [101]
-(57): warning: bit-field initializer does not fit [180]
diff -r 4921a20f98b3 -r c57bbd801760 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Fri Jan 01 17:21:47 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Fri Jan 01 19:11:19 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.51 2021/01/01 16:50:47 rillig Exp $ */
+/*     $NetBSD: init.c,v 1.52 2021/01/01 19:11:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.51 2021/01/01 16:50:47 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.52 2021/01/01 19:11:19 rillig Exp $");
 #endif
 
 #include <ctype.h>
@@ -109,8 +109,8 @@
        } else {
                namlist_t *nam = namedmem;
                namedmem = namedmem->n_next;
-               namedmem->n_next = nam->n_next; /* FIXME: inner circle */
-               namedmem->n_prev = nam->n_prev;
+               nam->n_prev->n_next = nam->n_next;
+               nam->n_next->n_prev = nam->n_prev;
                free(nam);
        }
 }



Home | Main Index | Thread Index | Old Index