This should fix most, if not all of the llvm-pdbdump-fuzzer errors. The problem is that we were not always checking that stream numbers were valid. This fixes that by making the constructor to MappedBlockStream private and only exposing it through a static creator which returns an Expected<unique_ptr<MappedBlockStream>>.
One problem that came up is that it's getting pretty ugly to write 4-5 lines of code to check an Expected<T> and return the error every time. I had the idea to wrap this up in some macros, but unfortunately it didn't go very well. You can see the results here. I could not find a way to do it without 6 different macros. If anyone can think of a way to make this less onerous, I'm all ears. Requirements:
- It should work if you have a failed Expected<T> and on error you return a failed Expected<U>, where T != U.
- It should work if you have a failed Expected<T> and you are returning an llvm::Error.
- It should work if T is a reference type, such as Expected<DbiStream&>.
- It should work if T is not copyable, such as Expected<std::unique_ptr<MappedBlockStream>>.
- It should work if you want the "success" value to go into an existing variable (such as a class member variable)
- It should work if you don't have a success variable declared and you want the macro to auto-declare it.