Closed frederic-mahe closed 4 years ago
For example, passing a empty header does not trigger the return false
(line 212):
(gdb) run -z <(printf ">\nA\n")
Breakpoint 3, find_usearch_abundance (header=0x7ffff799c014 "", start=0x7fffffffd7ac, end=0x7fffffffd7a8, number=0x7fffffffd7a0) at db.cc:211
211 if ((! header) || (! attribute))
(gdb) print header
$3 = 0x7ffff799c014 ""
(gdb) s
214 uint64_t hlen = strlen(header);
(gdb)
Yes, attribute
is always set, so the second part of the condition is always true. I will remove it.
Regarding the example: An empty string is still a string (not a zero pointer) so header will still be set.
Fixed now.
The check is meant to capture internal coding errors, not empty headers.
The check is meant to capture internal coding errors, not empty headers.
Thanks, it makes sense. Then, would it be a good opportunity to use an assert
?
assert(header) /* else something is very wrong */
If I understand correctly, assertions are not evaluated at runtime, unless compiled with NDEBUG
. So there is no performance penalty when using assert()
, where there can be some when using conditionals branching to capture coding errors.
Maybe assert would be fine here, but the overhead is negligible and I prefer the function to return false if the parameters are illegal.
That makes sense. Thanks!
https://github.com/torognes/swarm/blob/10f1d85d6233105d124facee21f97ca52f8ce849/src/db.cc#L211
Isn't attribute always set? Hence, the second part of the condition (
or not attribute
) is not necessary?