Repository navigation
benchfn: don't memset a NULL dst buffer of size 0 - #4826
xhon-pelushi wants to merge 1 commit into
Conversation
Some fullbench scenarios (convertSequences, get1BlockSummary) do not need a destination buffer, so their preparation leaves dst == NULL and dstCapacity == 0. BMK_benchFunction() then called memset(NULL, 0xE5, 0). Passing a null pointer to memset() is undefined behavior even when the length is 0, and UBSan reports it through glibc's nonnull annotation: programs/benchfn.c:116:13: runtime error: null pointer passed as argument 1, which is declared to never be null Skip the warm-up memset when the destination capacity is 0. Fixes meta#4776
|
Hi @xhon-pelushi! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
@Cyan4973 — memset on a NULL dst with size 0 is UB even when the size is zero; skipping it is the right call. Two lines, no behavior change otherwise. Looks mergeable to me. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Fixes #4776
Two fullbench scenarios, 18
convertSequences (1st block)and 19get1BlockSummary (1st block), prepare their inputs withprepConvertSequences(), which never sets a destination buffer:dststaysNULLanddstCapacitystays0(both benched functions ignoredst).BMK_benchFunction()inprograms/benchfn.cthen does the warm-upi.e.
memset(NULL, 0xE5, 0). Passing a null pointer tomemset()is undefined behavior even with a length of 0, and UBSan flags it via glibc'snonnullannotation.This skips the warm-up
memsetwhen the destination capacity is 0.I fixed it in
benchfn.crather than givingprepConvertSequences()a dummy buffer, so any other benchmark with an empty destination is covered too. Happy to switch to the other approach if you prefer.Testing, building
tests/fullbenchwithMOREFLAGS="-fsanitize=undefined -fno-sanitize-recover=all -g"(gcc 13.3):dev(01b7154):./fullbench -i1 -b18and-b19each exit 1 with../programs/benchfn.c:116:13: runtime error: null pointer passed as argument 1, which is declared to never be null-b18,-b19and the full./fullbench -i1run all exit 0 with no UBSan report