Fix DataExtractor::PeekData for zero length peeks
authorPavel Labath <labath@google.com>
Tue, 26 Jul 2016 08:11:57 +0000 (08:11 +0000)
committerPavel Labath <labath@google.com>
Tue, 26 Jul 2016 08:11:57 +0000 (08:11 +0000)
commitf7e7fdd5cfebf4a8a30e4b4dce410a237f13a17c
tree292207befa0aff5545df77cd99b19009691ab0d2
parent79011a660eda556f553fe52f090cb4156f12c1ab
Fix DataExtractor::PeekData for zero length peeks

Summary:
The function was returning the null pointer for peeks of size zero, which seems like a sensible
thing to do, but is actually pretty easy to get bitten by that if you are extracting a variable
length field which happens to be of zero length and then doing pointer arithmetic on that (which
SymbolFileDWARF does, and ended up crashing in case of empty DW_AT_location).

This changes the function to return a null pointer only when it gets queried for data which is
outside of the range of the extractor, which is more c++-y, as one can still do reasonable things
with pointers to data of size zero (think, end() iterators).

I also add a test and fix some signedness warnings in the existing data extractor tests.

Reviewers: clayborg

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D22755

llvm-svn: 276734
lldb/include/lldb/Core/DataExtractor.h
lldb/unittests/Core/DataExtractorTest.cpp