]> git.ozlabs.org Git - ccan/commit
opt: fix opt_unregister.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 11 Feb 2020 04:09:43 +0000 (14:39 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 11 Feb 2020 04:09:43 +0000 (14:39 +1030)
commit4f20b75c6133425f2b8c369bb1ecfbd7d3410353
tree2a3bc867a040f15320d76de685e3a59af47a5bee
parente5fb923ba3735c758ef795eb69d5ee1c6f0a94e9
opt: fix opt_unregister.

Instead of memmoving N structs, we were memmoving N bytes.

But why did the test pass then?  It was doing memmove(..., 1)
instead of memmove(..., sizeof(struct opt_table)!

Because the two structures were really similar; the main difference
was the first entry, which points to the name.  But they were allocated
consecutively, and Intel being little-endian, the only difference was
the first byte!  Thus memmove(1) was enough to make it "work".

Change two options in the test to be sufficiently different, and
the bug shows up.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/opt/opt.c
ccan/opt/test/run-unregister.c