summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e5fb923)
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>
if (found == -1)
return false;
opt_count--;
if (found == -1)
return false;
opt_count--;
- memmove(&opt_table[found], &opt_table[found+1], opt_count - found);
+ memmove(&opt_table[found], &opt_table[found+1],
+ (opt_count - found) * sizeof(opt_table[found]));
{
const char *myname = argv[0];
{
const char *myname = argv[0];
opt_register_noarg("--aaa|-a", test_noarg, NULL, "AAAAAAll");
opt_register_noarg("--aaa|-a", test_noarg, NULL, "AAAAAAll");
- opt_register_noarg("-b", test_noarg, NULL, "AAAAAAll");
+ opt_register_arg("-b", test_arg, NULL, "bbb", "b");
/* We can't unregister wrong ones, but can unregister correct one */
ok1(!opt_unregister("--aaa"));
/* We can't unregister wrong ones, but can unregister correct one */
ok1(!opt_unregister("--aaa"));
ok1(opt_unregister("--aaa|-a"));
/* Arg parsing works as if we'd never registered it */
ok1(opt_unregister("--aaa|-a"));
/* Arg parsing works as if we'd never registered it */
- ok1(parse_args(&argc, &argv, "-b", NULL));
+ ok1(parse_args(&argc, &argv, "-bbbb", NULL));
ok1(argc == 1);
ok1(argv[0] == myname);
ok1(argv[1] == NULL);
ok1(argc == 1);
ok1(argv[0] == myname);
ok1(argv[1] == NULL);